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