mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
1import React, {useCallback} from 'react'
2import {View} from 'react-native'
3import {msg, Trans} from '@lingui/macro'
4import {useLingui} from '@lingui/react'
5
6import {
7 type EmbedPlayerSource,
8 embedPlayerSources,
9 externalEmbedLabels,
10} from '#/lib/strings/embed-player'
11import {useSetExternalEmbedPref} from '#/state/preferences'
12import {atoms as a, useBreakpoints, useTheme} from '#/alf'
13import * as Dialog from '#/components/Dialog'
14import {Button, ButtonText} from '../Button'
15import {Text} from '../Typography'
16
17export function EmbedConsentDialog({
18 control,
19 source,
20 onAccept,
21}: {
22 control: Dialog.DialogControlProps
23 source: EmbedPlayerSource
24 onAccept: () => void
25}) {
26 const {_} = useLingui()
27 const t = useTheme()
28 const setExternalEmbedPref = useSetExternalEmbedPref()
29 const {gtMobile} = useBreakpoints()
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}>
52 <Dialog.Handle />
53
54 <Dialog.ScrollableInner
55 label={_(msg`External Media`)}
56 style={[gtMobile ? {width: 'auto', maxWidth: 400} : a.w_full]}>
57 <View style={a.gap_sm}>
58 <Text style={[a.text_2xl, a.font_bold]}>
59 <Trans>External Media</Trans>
60 </Text>
61
62 <View style={[a.mt_sm, a.mb_2xl, a.gap_lg]}>
63 <Text>
64 <Trans>
65 This content is hosted by {externalEmbedLabels[source]}. Do you
66 want to enable external media?
67 </Trans>
68 </Text>
69
70 <Text style={t.atoms.text_contrast_medium}>
71 <Trans>
72 External media may allow websites to collect information about
73 you and your device. No information is sent or requested until
74 you press the "play" button.
75 </Trans>
76 </Text>
77 </View>
78 </View>
79 <View style={a.gap_md}>
80 <Button
81 style={gtMobile && a.flex_1}
82 label={_(msg`Enable external media`)}
83 onPress={onShowAllPress}
84 onAccessibilityEscape={control.close}
85 color="primary"
86 size="medium"
87 variant="solid">
88 <ButtonText>
89 <Trans>Enable external media</Trans>
90 </ButtonText>
91 </Button>
92 <Button
93 style={gtMobile && a.flex_1}
94 label={_(msg`Enable this source only`)}
95 onPress={onShowPress}
96 onAccessibilityEscape={control.close}
97 color="secondary"
98 size="medium"
99 variant="solid">
100 <ButtonText>
101 <Trans>Enable {externalEmbedLabels[source]} only</Trans>
102 </ButtonText>
103 </Button>
104 <Button
105 label={_(msg`No thanks`)}
106 onAccessibilityEscape={control.close}
107 onPress={onHidePress}
108 color="secondary"
109 size="medium"
110 variant="ghost">
111 <ButtonText>
112 <Trans>No thanks</Trans>
113 </ButtonText>
114 </Button>
115 </View>
116 </Dialog.ScrollableInner>
117 </Dialog.Outer>
118 )
119}