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