mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {View} from 'react-native'
3import {AppBskyLabelerDefs} from '@atproto/api'
4import {msg, Trans} from '@lingui/macro'
5import {useLingui} from '@lingui/react'
6
7import {ReportOption, useReportOptions} from '#/lib/moderation/useReportOptions'
8import {Link} from '#/components/Link'
9import {DMCA_LINK} from '#/components/ReportDialog/const'
10export {useDialogControl as useReportDialogControl} from '#/components/Dialog'
11
12import {atoms as a, useBreakpoints, useTheme} from '#/alf'
13import {
14 Button,
15 ButtonIcon,
16 ButtonText,
17 useButtonContext,
18} from '#/components/Button'
19import {Divider} from '#/components/Divider'
20import {
21 ChevronLeft_Stroke2_Corner0_Rounded as ChevronLeft,
22 ChevronRight_Stroke2_Corner0_Rounded as ChevronRight,
23} from '#/components/icons/Chevron'
24import {SquareArrowTopRight_Stroke2_Corner0_Rounded as SquareArrowTopRight} from '#/components/icons/SquareArrowTopRight'
25import {Text} from '#/components/Typography'
26import {ReportDialogProps} from './types'
27
28type ParamsWithMessages = ReportDialogProps['params'] | {type: 'message'}
29
30export function SelectReportOptionView({
31 ...props
32}: {
33 params: ParamsWithMessages
34 labelers: AppBskyLabelerDefs.LabelerViewDetailed[]
35 onSelectReportOption: (reportOption: ReportOption) => void
36 goBack: () => void
37}) {
38 const t = useTheme()
39 const {_} = useLingui()
40 const {gtMobile} = useBreakpoints()
41 const allReportOptions = useReportOptions()
42 const reportOptions = allReportOptions[props.params.type]
43
44 const i18n = React.useMemo(() => {
45 let title = _(msg`Report this content`)
46 let description = _(msg`Why should this content be reviewed?`)
47
48 if (props.params.type === 'account') {
49 title = _(msg`Report this user`)
50 description = _(msg`Why should this user be reviewed?`)
51 } else if (props.params.type === 'post') {
52 title = _(msg`Report this post`)
53 description = _(msg`Why should this post be reviewed?`)
54 } else if (props.params.type === 'list') {
55 title = _(msg`Report this list`)
56 description = _(msg`Why should this list be reviewed?`)
57 } else if (props.params.type === 'feedgen') {
58 title = _(msg`Report this feed`)
59 description = _(msg`Why should this feed be reviewed?`)
60 } else if (props.params.type === 'message') {
61 title = _(msg`Report this message`)
62 description = _(msg`Why should this message be reviewed?`)
63 }
64
65 return {
66 title,
67 description,
68 }
69 }, [_, props.params.type])
70
71 return (
72 <View style={[a.gap_lg]}>
73 {props.labelers?.length > 1 ? (
74 <Button
75 size="small"
76 variant="solid"
77 color="secondary"
78 shape="round"
79 label={_(msg`Go back to previous step`)}
80 onPress={props.goBack}>
81 <ButtonIcon icon={ChevronLeft} />
82 </Button>
83 ) : null}
84
85 <View style={[a.justify_center, gtMobile ? a.gap_sm : a.gap_xs]}>
86 <Text style={[a.text_2xl, a.font_bold]}>{i18n.title}</Text>
87 <Text style={[a.text_md, t.atoms.text_contrast_medium]}>
88 {i18n.description}
89 </Text>
90 </View>
91
92 <Divider />
93
94 <View style={[a.gap_sm]}>
95 {reportOptions.map(reportOption => {
96 return (
97 <Button
98 key={reportOption.reason}
99 testID={reportOption.reason}
100 label={_(msg`Create report for ${reportOption.title}`)}
101 onPress={() => props.onSelectReportOption(reportOption)}>
102 <ReportOptionButton
103 title={reportOption.title}
104 description={reportOption.description}
105 />
106 </Button>
107 )
108 })}
109
110 {(props.params.type === 'post' || props.params.type === 'account') && (
111 <View
112 style={[
113 a.flex_row,
114 a.align_center,
115 a.justify_between,
116 a.gap_lg,
117 a.p_md,
118 a.pl_lg,
119 a.rounded_md,
120 t.atoms.bg_contrast_900,
121 ]}>
122 <Text
123 style={[
124 a.flex_1,
125 t.atoms.text_inverted,
126 a.italic,
127 a.leading_snug,
128 ]}>
129 <Trans>Need to report a copyright violation?</Trans>
130 </Text>
131 <Link
132 to={DMCA_LINK}
133 label={_(msg`View details for reporting a copyright violation`)}
134 size="small"
135 variant="solid"
136 color="secondary">
137 <ButtonText>
138 <Trans>View details</Trans>
139 </ButtonText>
140 <ButtonIcon position="right" icon={SquareArrowTopRight} />
141 </Link>
142 </View>
143 )}
144 </View>
145 </View>
146 )
147}
148
149function ReportOptionButton({
150 title,
151 description,
152}: {
153 title: string
154 description: string
155}) {
156 const t = useTheme()
157 const {hovered, pressed} = useButtonContext()
158 const interacted = hovered || pressed
159
160 return (
161 <View
162 style={[
163 a.w_full,
164 a.flex_row,
165 a.align_center,
166 a.justify_between,
167 a.p_md,
168 a.rounded_md,
169 {paddingRight: 70},
170 t.atoms.bg_contrast_25,
171 interacted && t.atoms.bg_contrast_50,
172 ]}>
173 <View style={[a.flex_1, a.gap_xs]}>
174 <Text style={[a.text_md, a.font_bold, t.atoms.text_contrast_medium]}>
175 {title}
176 </Text>
177 <Text style={[a.leading_tight, {maxWidth: 400}]}>{description}</Text>
178 </View>
179
180 <View
181 style={[
182 a.absolute,
183 a.inset_0,
184 a.justify_center,
185 a.pr_md,
186 {left: 'auto'},
187 ]}>
188 <ChevronRight size="md" fill={t.atoms.text_contrast_low.color} />
189 </View>
190 </View>
191 )
192}