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