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
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
|
import {Keyboard, View} from 'react-native'
import {msg, Trans} from '@lingui/macro'
import {useLingui} from '@lingui/react'
import {
ADULT_CONTENT_LABELS,
type AdultSelfLabel,
OTHER_SELF_LABELS,
type OtherSelfLabel,
type SelfLabel,
} from '#/lib/moderation'
import {isWeb} from '#/platform/detection'
import {atoms as a, native, useTheme, web} from '#/alf'
import {Button, ButtonIcon, ButtonText} from '#/components/Button'
import * as Dialog from '#/components/Dialog'
import * as Toggle from '#/components/forms/Toggle'
import {Check_Stroke2_Corner0_Rounded as Check} from '#/components/icons/Check'
import {Shield_Stroke2_Corner0_Rounded} from '#/components/icons/Shield'
import {Text} from '#/components/Typography'
export function LabelsBtn({
labels,
onChange,
}: {
labels: SelfLabel[]
onChange: (v: SelfLabel[]) => void
}) {
const control = Dialog.useDialogControl()
const {_} = useLingui()
const hasLabel = labels.length > 0
const updateAdultLabels = (newLabels: AdultSelfLabel[]) => {
const newLabel = newLabels[newLabels.length - 1]
const filtered = labels.filter(l => !ADULT_CONTENT_LABELS.includes(l))
onChange([
...new Set([...filtered, newLabel].filter(Boolean) as SelfLabel[]),
])
}
const updateOtherLabels = (newLabels: OtherSelfLabel[]) => {
const newLabel = newLabels[newLabels.length - 1]
const filtered = labels.filter(l => !OTHER_SELF_LABELS.includes(l))
onChange([
...new Set([...filtered, newLabel].filter(Boolean) as SelfLabel[]),
])
}
return (
<>
<Button
variant="solid"
color="secondary"
size="small"
testID="labelsBtn"
onPress={() => {
Keyboard.dismiss()
control.open()
}}
label={_(msg`Content warnings`)}
accessibilityHint={_(
msg`Opens a dialog to add a content warning to your post`,
)}
style={[
native({
paddingHorizontal: 8,
paddingVertical: 6,
}),
]}>
<ButtonIcon icon={hasLabel ? Check : Shield_Stroke2_Corner0_Rounded} />
<ButtonText numberOfLines={1}>
{labels.length > 0 ? (
<Trans>Labels added</Trans>
) : (
<Trans>Labels</Trans>
)}
</ButtonText>
</Button>
<Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}>
<Dialog.Handle />
<DialogInner
labels={labels}
updateAdultLabels={updateAdultLabels}
updateOtherLabels={updateOtherLabels}
/>
</Dialog.Outer>
</>
)
}
function DialogInner({
labels,
updateAdultLabels,
updateOtherLabels,
}: {
labels: string[]
updateAdultLabels: (labels: AdultSelfLabel[]) => void
updateOtherLabels: (labels: OtherSelfLabel[]) => void
}) {
const {_} = useLingui()
const control = Dialog.useDialogContext()
const t = useTheme()
return (
<Dialog.ScrollableInner
label={_(msg`Add a content warning`)}
style={[{maxWidth: 500}, a.w_full]}>
<View style={[a.flex_1]}>
<View style={[a.gap_sm]}>
<Text style={[a.text_2xl, a.font_bold]}>
<Trans>Add a content warning</Trans>
</Text>
<Text style={[t.atoms.text_contrast_medium, a.leading_snug]}>
<Trans>
Please add any content warning labels that are applicable for the
media you are posting.
</Trans>
</Text>
</View>
<View style={[a.my_md, a.gap_lg]}>
<View>
<View
style={[a.flex_row, a.align_center, a.justify_between, a.pb_sm]}>
<Text style={[a.font_bold, a.text_lg]}>
<Trans>Adult Content</Trans>
</Text>
</View>
<View
style={[
a.p_md,
a.rounded_sm,
a.border,
t.atoms.border_contrast_medium,
]}>
<Toggle.Group
label={_(msg`Adult Content labels`)}
values={labels}
onChange={values => {
updateAdultLabels(values as AdultSelfLabel[])
}}>
<View style={[a.gap_sm]}>
<Toggle.Item name="sexual" label={_(msg`Suggestive`)}>
<Toggle.Checkbox />
<Toggle.LabelText>
<Trans>Suggestive</Trans>
</Toggle.LabelText>
</Toggle.Item>
<Toggle.Item name="nudity" label={_(msg`Nudity`)}>
<Toggle.Checkbox />
<Toggle.LabelText>
<Trans>Nudity</Trans>
</Toggle.LabelText>
</Toggle.Item>
<Toggle.Item name="porn" label={_(msg`Porn`)}>
<Toggle.Checkbox />
<Toggle.LabelText>
<Trans>Adult</Trans>
</Toggle.LabelText>
</Toggle.Item>
</View>
</Toggle.Group>
{labels.includes('sexual') ||
labels.includes('nudity') ||
labels.includes('porn') ? (
<Text style={[a.mt_sm, t.atoms.text_contrast_medium]}>
{labels.includes('sexual') ? (
<Trans>Pictures meant for adults.</Trans>
) : labels.includes('nudity') ? (
<Trans>Artistic or non-erotic nudity.</Trans>
) : labels.includes('porn') ? (
<Trans>Sexual activity or erotic nudity.</Trans>
) : (
''
)}
</Text>
) : null}
</View>
</View>
<View>
<View
style={[a.flex_row, a.align_center, a.justify_between, a.pb_sm]}>
<Text style={[a.font_bold, a.text_lg]}>
<Trans>Other</Trans>
</Text>
</View>
<View
style={[
a.p_md,
a.rounded_sm,
a.border,
t.atoms.border_contrast_medium,
]}>
<Toggle.Group
label={_(msg`Adult Content labels`)}
values={labels}
onChange={values => {
updateOtherLabels(values as OtherSelfLabel[])
}}>
<Toggle.Item name="graphic-media" label={_(msg`Graphic Media`)}>
<Toggle.Checkbox />
<Toggle.LabelText>
<Trans>Graphic Media</Trans>
</Toggle.LabelText>
</Toggle.Item>
</Toggle.Group>
{labels.includes('graphic-media') ? (
<Text style={[a.mt_sm, t.atoms.text_contrast_medium]}>
<Trans>
Media that may be disturbing or inappropriate for some
audiences.
</Trans>
</Text>
) : null}
</View>
</View>
</View>
</View>
<View style={[a.mt_sm, web([a.flex_row, a.ml_auto])]}>
<Button
label={_(msg`Done`)}
onPress={() => control.close()}
color="primary"
size={isWeb ? 'small' : 'large'}
variant="solid"
testID="confirmBtn">
<ButtonText>
<Trans>Done</Trans>
</ButtonText>
</Button>
</View>
</Dialog.ScrollableInner>
)
}
|