mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React from 'react'
2import {
3 StyleProp,
4 TouchableWithoutFeedback,
5 View,
6 ViewStyle,
7} from 'react-native'
8import {ModerationUI} from '@atproto/api'
9import {msg, Trans} from '@lingui/macro'
10import {useLingui} from '@lingui/react'
11import {useNavigation} from '@react-navigation/native'
12
13import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
14import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
15import {NavigationProp} from '#/lib/routes/types'
16import {CenteredView} from '#/view/com/util/Views'
17import {atoms as a, useTheme, web} from '#/alf'
18import {Button, ButtonText} from '#/components/Button'
19import {
20 ModerationDetailsDialog,
21 useModerationDetailsDialogControl,
22} from '#/components/moderation/ModerationDetailsDialog'
23import {Text} from '#/components/Typography'
24
25export function ScreenHider({
26 testID,
27 screenDescription,
28 modui,
29 style,
30 containerStyle,
31 children,
32}: React.PropsWithChildren<{
33 testID?: string
34 screenDescription: string
35 modui: ModerationUI
36 style?: StyleProp<ViewStyle>
37 containerStyle?: StyleProp<ViewStyle>
38}>) {
39 const t = useTheme()
40 const {_} = useLingui()
41 const [override, setOverride] = React.useState(false)
42 const navigation = useNavigation<NavigationProp>()
43 const {isMobile} = useWebMediaQueries()
44 const control = useModerationDetailsDialogControl()
45 const blur = modui.blurs[0]
46 const desc = useModerationCauseDescription(blur)
47
48 if (!blur || override) {
49 return (
50 <View testID={testID} style={style}>
51 {children}
52 </View>
53 )
54 }
55
56 const isNoPwi = !!modui.blurs.find(
57 cause =>
58 cause.type === 'label' &&
59 cause.labelDef.identifier === '!no-unauthenticated',
60 )
61 return (
62 <CenteredView
63 style={[
64 a.flex_1,
65 {
66 paddingTop: 100,
67 paddingBottom: 150,
68 },
69 t.atoms.bg,
70 containerStyle,
71 ]}
72 sideBorders>
73 <View style={[a.align_center, a.mb_md]}>
74 <View
75 style={[
76 t.atoms.bg_contrast_975,
77 a.align_center,
78 a.justify_center,
79 {
80 borderRadius: 25,
81 width: 50,
82 height: 50,
83 },
84 ]}>
85 <desc.icon width={24} fill={t.atoms.bg.backgroundColor} />
86 </View>
87 </View>
88 <Text
89 style={[a.text_4xl, a.font_bold, a.text_center, a.mb_md, t.atoms.text]}>
90 {isNoPwi ? (
91 <Trans>Sign-in Required</Trans>
92 ) : (
93 <Trans>Content Warning</Trans>
94 )}
95 </Text>
96 <Text
97 style={[
98 a.text_lg,
99 a.mb_md,
100 a.px_lg,
101 a.text_center,
102 a.leading_snug,
103 t.atoms.text_contrast_medium,
104 ]}>
105 {isNoPwi ? (
106 <Trans>
107 This account has requested that users sign in to view their profile.
108 </Trans>
109 ) : (
110 <>
111 <Trans>This {screenDescription} has been flagged:</Trans>{' '}
112 <Text
113 style={[
114 a.text_lg,
115 a.font_bold,
116 a.leading_snug,
117 t.atoms.text,
118 a.ml_xs,
119 ]}>
120 {desc.name}.{' '}
121 </Text>
122 <TouchableWithoutFeedback
123 onPress={() => {
124 control.open()
125 }}
126 accessibilityRole="button"
127 accessibilityLabel={_(msg`Learn more about this warning`)}
128 accessibilityHint="">
129 <Text
130 style={[
131 a.text_lg,
132 a.leading_snug,
133 {
134 color: t.palette.primary_500,
135 },
136 web({
137 cursor: 'pointer',
138 }),
139 ]}>
140 <Trans>Learn More</Trans>
141 </Text>
142 </TouchableWithoutFeedback>
143 <ModerationDetailsDialog control={control} modcause={blur} />
144 </>
145 )}{' '}
146 </Text>
147 {isMobile && <View style={a.flex_1} />}
148 <View style={[a.flex_row, a.justify_center, a.my_md, a.gap_md]}>
149 <Button
150 variant="solid"
151 color="primary"
152 size="large"
153 style={[a.rounded_full]}
154 label={_(msg`Go back`)}
155 onPress={() => {
156 if (navigation.canGoBack()) {
157 navigation.goBack()
158 } else {
159 navigation.navigate('Home')
160 }
161 }}>
162 <ButtonText>
163 <Trans>Go back</Trans>
164 </ButtonText>
165 </Button>
166 {!modui.noOverride && (
167 <Button
168 variant="solid"
169 color="secondary"
170 size="large"
171 style={[a.rounded_full]}
172 label={_(msg`Show anyway`)}
173 onPress={() => setOverride(v => !v)}>
174 <ButtonText>
175 <Trans>Show anyway</Trans>
176 </ButtonText>
177 </Button>
178 )}
179 </View>
180 </CenteredView>
181 )
182}