about summary refs log tree commit diff
path: root/src/components/moderation/ScreenHider.tsx
blob: 5680b60c2db3d81807b21e21dd15fc422cbb4230 (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
import React from 'react'
import {
  StyleProp,
  TouchableWithoutFeedback,
  View,
  ViewStyle,
} from 'react-native'
import {ModerationUI} from '@atproto/api'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {useNavigation} from '@react-navigation/native'

import {useWebMediaQueries} from '#/lib/hooks/useWebMediaQueries'
import {useModerationCauseDescription} from '#/lib/moderation/useModerationCauseDescription'
import {NavigationProp} from '#/lib/routes/types'
import {CenteredView} from '#/view/com/util/Views'
import {atoms as a, useTheme, web} from '#/alf'
import {Button, ButtonText} from '#/components/Button'
import {
  ModerationDetailsDialog,
  useModerationDetailsDialogControl,
} from '#/components/moderation/ModerationDetailsDialog'
import {Text} from '#/components/Typography'

export function ScreenHider({
  testID,
  screenDescription,
  modui,
  style,
  containerStyle,
  children,
}: React.PropsWithChildren<{
  testID?: string
  screenDescription: string
  modui: ModerationUI
  style?: StyleProp<ViewStyle>
  containerStyle?: StyleProp<ViewStyle>
}>) {
  const t = useTheme()
  const {_} = useLingui()
  const [override, setOverride] = React.useState(false)
  const navigation = useNavigation<NavigationProp>()
  const {isMobile} = useWebMediaQueries()
  const control = useModerationDetailsDialogControl()
  const blur = modui.blurs[0]
  const desc = useModerationCauseDescription(blur)

  if (!blur || override) {
    return (
      <View testID={testID} style={style}>
        {children}
      </View>
    )
  }

  const isNoPwi = !!modui.blurs.find(
    cause =>
      cause.type === 'label' &&
      cause.labelDef.identifier === '!no-unauthenticated',
  )
  return (
    <CenteredView
      style={[
        a.flex_1,
        {
          paddingTop: 100,
          paddingBottom: 150,
        },
        t.atoms.bg,
        containerStyle,
      ]}
      sideBorders>
      <View style={[a.align_center, a.mb_md]}>
        <View
          style={[
            t.atoms.bg_contrast_975,
            a.align_center,
            a.justify_center,
            {
              borderRadius: 25,
              width: 50,
              height: 50,
            },
          ]}>
          <desc.icon width={24} fill={t.atoms.bg.backgroundColor} />
        </View>
      </View>
      <Text
        style={[a.text_4xl, a.font_bold, a.text_center, a.mb_md, t.atoms.text]}>
        {isNoPwi ? (
          <Trans>Sign-in Required</Trans>
        ) : (
          <Trans>Content Warning</Trans>
        )}
      </Text>
      <Text
        style={[
          a.text_lg,
          a.mb_md,
          a.px_lg,
          a.text_center,
          a.leading_snug,
          t.atoms.text_contrast_medium,
        ]}>
        {isNoPwi ? (
          <Trans>
            This account has requested that users sign in to view their profile.
          </Trans>
        ) : (
          <>
            <Trans>This {screenDescription} has been flagged:</Trans>{' '}
            <Text
              style={[
                a.text_lg,
                a.font_bold,
                a.leading_snug,
                t.atoms.text,
                a.ml_xs,
              ]}>
              {desc.name}.{' '}
            </Text>
            <TouchableWithoutFeedback
              onPress={() => {
                control.open()
              }}
              accessibilityRole="button"
              accessibilityLabel={_(msg`Learn more about this warning`)}
              accessibilityHint="">
              <Text
                style={[
                  a.text_lg,
                  a.leading_snug,
                  {
                    color: t.palette.primary_500,
                  },
                  web({
                    cursor: 'pointer',
                  }),
                ]}>
                <Trans>Learn More</Trans>
              </Text>
            </TouchableWithoutFeedback>
            <ModerationDetailsDialog control={control} modcause={blur} />
          </>
        )}{' '}
      </Text>
      {isMobile && <View style={a.flex_1} />}
      <View style={[a.flex_row, a.justify_center, a.my_md, a.gap_md]}>
        <Button
          variant="solid"
          color="primary"
          size="large"
          style={[a.rounded_full]}
          label={_(msg`Go back`)}
          onPress={() => {
            if (navigation.canGoBack()) {
              navigation.goBack()
            } else {
              navigation.navigate('Home')
            }
          }}>
          <ButtonText>
            <Trans>Go back</Trans>
          </ButtonText>
        </Button>
        {!modui.noOverride && (
          <Button
            variant="solid"
            color="secondary"
            size="large"
            style={[a.rounded_full]}
            label={_(msg`Show anyway`)}
            onPress={() => setOverride(v => !v)}>
            <ButtonText>
              <Trans>Show anyway</Trans>
            </ButtonText>
          </Button>
        )}
      </View>
    </CenteredView>
  )
}