forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {useCallback} from 'react'
2import {View} from 'react-native'
3import {msg} from '@lingui/core/macro'
4import {useLingui} from '@lingui/react'
5import {Trans} from '@lingui/react/macro'
6
7import {
8 type EmbedPlayerSource,
9 embedPlayerSources,
10 externalEmbedLabels,
11} from '#/lib/strings/embed-player'
12import {useSetExternalEmbedPref} from '#/state/preferences'
13import {atoms as a, web} from '#/alf'
14import {Admonition} from '#/components/Admonition'
15import {Button, ButtonText} from '#/components/Button'
16import * as Dialog from '#/components/Dialog'
17import {Text} from '#/components/Typography'
18
19export function EmbedConsentDialog({
20 control,
21 source,
22 onAccept,
23}: {
24 control: Dialog.DialogControlProps
25 source: EmbedPlayerSource
26 onAccept: () => void
27}) {
28 const {_} = useLingui()
29 const setExternalEmbedPref = useSetExternalEmbedPref()
30
31 const onShowAllPress = useCallback(() => {
32 for (const key of embedPlayerSources) {
33 setExternalEmbedPref(key, 'show')
34 }
35 onAccept()
36 control.close()
37 }, [control, onAccept, setExternalEmbedPref])
38
39 const onShowPress = useCallback(() => {
40 setExternalEmbedPref(source, 'show')
41 onAccept()
42 control.close()
43 }, [control, onAccept, setExternalEmbedPref, source])
44
45 const onHidePress = useCallback(() => {
46 setExternalEmbedPref(source, 'hide')
47 control.close()
48 }, [control, setExternalEmbedPref, source])
49
50 return (
51 <Dialog.Outer control={control} nativeOptions={{preventExpansion: true}}>
52 <Dialog.Handle />
53 <Dialog.ScrollableInner
54 label={_(msg`External Media`)}
55 style={web({maxWidth: 400})}>
56 <View style={a.gap_sm}>
57 <Text style={[a.text_2xl, a.font_bold]}>
58 <Trans>External Media</Trans>
59 </Text>
60
61 <View style={[a.mt_sm, a.mb_2xl, a.gap_lg]}>
62 <Text style={[a.text_md, a.leading_snug]}>
63 <Trans>
64 This content is hosted by {externalEmbedLabels[source]}. Do you
65 want to enable external media?
66 </Trans>
67 </Text>
68
69 <Admonition type="info">
70 <Trans>
71 External media may allow websites to collect information about
72 you and your device. No information is sent or requested until
73 you press the "play" button.
74 </Trans>
75 </Admonition>
76 </View>
77 </View>
78 <View style={a.gap_md}>
79 <Button
80 label={_(msg`Enable external media`)}
81 onPress={onShowAllPress}
82 onAccessibilityEscape={control.close}
83 color="primary"
84 size="large">
85 <ButtonText>
86 <Trans>Enable external media</Trans>
87 </ButtonText>
88 </Button>
89 <Button
90 label={_(msg`Enable this source only`)}
91 onPress={onShowPress}
92 onAccessibilityEscape={control.close}
93 color="secondary"
94 size="large">
95 <ButtonText>
96 <Trans>Enable {externalEmbedLabels[source]} only</Trans>
97 </ButtonText>
98 </Button>
99 <Button
100 label={_(msg`No thanks`)}
101 onAccessibilityEscape={control.close}
102 onPress={onHidePress}
103 color="secondary"
104 size="large"
105 variant="ghost">
106 <ButtonText>
107 <Trans>No thanks</Trans>
108 </ButtonText>
109 </Button>
110 </View>
111 <Dialog.Close />
112 </Dialog.ScrollableInner>
113 </Dialog.Outer>
114 )
115}