+27
-9
src/screens/Settings/ExternalMediaPreferences.tsx
+27
-9
src/screens/Settings/ExternalMediaPreferences.tsx
···
1
-
import {Fragment} from 'react'
1
+
import {Fragment, useCallback} from 'react'
2
2
import {View} from 'react-native'
3
3
import {Trans} from '@lingui/macro'
4
4
···
8
8
} from '#/lib/routes/types'
9
9
import {
10
10
type EmbedPlayerSource,
11
+
embedPlayerSources,
11
12
externalEmbedLabels,
12
13
} from '#/lib/strings/embed-player'
13
14
import {
···
53
54
</SettingsList.ItemText>
54
55
<View style={[a.mt_sm, a.w_full]}>
55
56
{native(<SettingsList.Divider style={[a.my_0]} />)}
57
+
<PrefSelector source="all" label="All" />
58
+
<SettingsList.Divider />
56
59
{Object.entries(externalEmbedLabels)
57
60
// TODO: Remove special case when we disable the old integration.
58
61
.filter(([key]) => key !== 'tenor')
···
78
81
source,
79
82
label,
80
83
}: {
81
-
source: EmbedPlayerSource
84
+
source: EmbedPlayerSource | 'all'
82
85
label: string
83
86
}) {
84
87
const setExternalEmbedPref = useSetExternalEmbedPref()
85
88
const sources = useExternalEmbedsPrefs()
86
89
90
+
const isChecked =
91
+
source === 'all'
92
+
? embedPlayerSources
93
+
.filter(key => key !== 'tenor')
94
+
.every(key => sources?.[key] === 'show')
95
+
: sources?.[source] === 'show'
96
+
97
+
const handleChange = useCallback(() => {
98
+
if (source === 'all') {
99
+
const newValue = isChecked ? 'hide' : 'show'
100
+
for (const key of embedPlayerSources) {
101
+
if (key !== 'tenor') {
102
+
setExternalEmbedPref(key, newValue)
103
+
}
104
+
}
105
+
} else {
106
+
setExternalEmbedPref(source, isChecked ? 'hide' : 'show')
107
+
}
108
+
}, [source, isChecked, setExternalEmbedPref])
109
+
87
110
return (
88
111
<Toggle.Item
89
112
name={label}
90
113
label={label}
91
114
type="checkbox"
92
-
value={sources?.[source] === 'show'}
93
-
onChange={() =>
94
-
setExternalEmbedPref(
95
-
source,
96
-
sources?.[source] === 'show' ? 'hide' : 'show',
97
-
)
98
-
}
115
+
value={isChecked}
116
+
onChange={handleChange}
99
117
style={[
100
118
a.flex_1,
101
119
a.py_md,