import {useMemo} from 'react' import {View} from 'react-native' import {type AppBskyNotificationDefs} from '@atproto/api' import {type FilterablePreference} from '@atproto/api/dist/client/types/app/bsky/notification/defs' import {msg, Trans} from '@lingui/macro' import {useLingui} from '@lingui/react' import {useNotificationSettingsUpdateMutation} from '#/state/queries/notifications/settings' import {atoms as a, platform, useTheme} from '#/alf' import * as Toggle from '#/components/forms/Toggle' import {Loader} from '#/components/Loader' import {Text} from '#/components/Typography' import {Divider} from '../../components/SettingsList' export function PreferenceControls({ name, syncOthers, preference, allowDisableInApp = true, }: { name: Exclude /** * Keep other prefs in sync with `name`. For use in the "everything else" category * which groups starterpack joins + verified + unverified notifications into a single toggle. */ syncOthers?: Exclude[] preference?: AppBskyNotificationDefs.Preference | FilterablePreference allowDisableInApp?: boolean }) { if (!preference) return ( ) return ( ) } export function Inner({ name, syncOthers = [], preference, allowDisableInApp, }: { name: Exclude syncOthers?: Exclude[] preference: AppBskyNotificationDefs.Preference | FilterablePreference allowDisableInApp: boolean }) { const t = useTheme() const {_} = useLingui() const {mutate} = useNotificationSettingsUpdateMutation() const channels = useMemo(() => { const arr = [] if (preference.list) arr.push('list') if (preference.push) arr.push('push') return arr }, [preference]) const onChangeChannels = (change: string[]) => { const newPreference = { ...preference, list: change.includes('list'), push: change.includes('push'), } satisfies typeof preference mutate({ [name]: newPreference, ...Object.fromEntries(syncOthers.map(key => [key, newPreference])), }) } const onChangeFilter = ([change]: string[]) => { if (change !== 'all' && change !== 'follows') throw new Error('Invalid filter') const newPreference = { ...preference, filter: change, } satisfies typeof preference mutate({ [name]: newPreference, ...Object.fromEntries(syncOthers.map(key => [key, newPreference])), }) } return ( Push notifications {allowDisableInApp && ( In-app notifications )} {'filter' in preference && ( <> From 0 && t.atoms.text, a.font_normal, a.text_md, ]}> Everyone 0 && t.atoms.text, a.font_normal, a.text_md, ]}> People I follow )} ) }