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