forked from
jollywhoppers.com/witchsky.app
Bluesky app fork with some witchin' additions 馃挮
1import {View} from 'react-native'
2import {type AppBskyNotificationDeclaration} from '@atproto/api'
3import {msg} from '@lingui/core/macro'
4import {useLingui} from '@lingui/react'
5import {Trans} from '@lingui/react/macro'
6
7import {
8 type AllNavigatorParams,
9 type NativeStackScreenProps,
10} from '#/lib/routes/types'
11import {
12 useNotificationDeclarationMutation,
13 useNotificationDeclarationQuery,
14} from '#/state/queries/activity-subscriptions'
15import {atoms as a, useTheme} from '#/alf'
16import {Admonition} from '#/components/Admonition'
17import * as Toggle from '#/components/forms/Toggle'
18import {BellRinging_Stroke2_Corner0_Rounded as BellRingingIcon} from '#/components/icons/BellRinging'
19import * as Layout from '#/components/Layout'
20import {Loader} from '#/components/Loader'
21import * as SettingsList from './components/SettingsList'
22import {ItemTextWithSubtitle} from './NotificationSettings/components/ItemTextWithSubtitle'
23
24type Props = NativeStackScreenProps<
25 AllNavigatorParams,
26 'ActivityPrivacySettings'
27>
28export function ActivityPrivacySettingsScreen({}: Props) {
29 const {
30 data: notificationDeclaration,
31 isPending,
32 isError,
33 } = useNotificationDeclarationQuery()
34
35 return (
36 <Layout.Screen>
37 <Layout.Header.Outer>
38 <Layout.Header.BackButton />
39 <Layout.Header.Content>
40 <Layout.Header.TitleText>
41 <Trans>Privacy and Security</Trans>
42 </Layout.Header.TitleText>
43 </Layout.Header.Content>
44 <Layout.Header.Slot />
45 </Layout.Header.Outer>
46 <Layout.Content>
47 <SettingsList.Container>
48 <SettingsList.Item style={[a.align_start]}>
49 <SettingsList.ItemIcon icon={BellRingingIcon} />
50 <ItemTextWithSubtitle
51 bold
52 titleText={
53 <Trans>Allow others to be notified of your posts</Trans>
54 }
55 subtitleText={
56 <Trans>
57 This feature allows users to receive notifications for your
58 new posts and replies. Who do you want to enable this for?
59 </Trans>
60 }
61 />
62 </SettingsList.Item>
63 <View style={[a.px_xl, a.pt_md]}>
64 {isError ? (
65 <Admonition type="error">
66 <Trans>Failed to load preference.</Trans>
67 </Admonition>
68 ) : isPending ? (
69 <View style={[a.w_full, a.pt_5xl, a.align_center]}>
70 <Loader size="xl" />
71 </View>
72 ) : (
73 <Inner notificationDeclaration={notificationDeclaration} />
74 )}
75 </View>
76 </SettingsList.Container>
77 </Layout.Content>
78 </Layout.Screen>
79 )
80}
81
82export function Inner({
83 notificationDeclaration,
84}: {
85 notificationDeclaration: {
86 uri?: string
87 cid?: string
88 value: AppBskyNotificationDeclaration.Record
89 }
90}) {
91 const t = useTheme()
92 const {_} = useLingui()
93 const {mutate} = useNotificationDeclarationMutation()
94
95 const onChangeFilter = ([declaration]: string[]) => {
96 mutate({
97 $type: 'app.bsky.notification.declaration',
98 allowSubscriptions: declaration,
99 })
100 }
101
102 return (
103 <Toggle.Group
104 type="radio"
105 label={_(
106 msg`Filter who can opt to receive notifications for your activity`,
107 )}
108 values={[notificationDeclaration.value.allowSubscriptions]}
109 onChange={onChangeFilter}>
110 <View style={[a.gap_sm]}>
111 <Toggle.Item
112 label={_(msg`Anyone who follows me`)}
113 name="followers"
114 style={[a.flex_row, a.py_xs, a.gap_sm]}>
115 <Toggle.Radio />
116 <Toggle.LabelText style={[t.atoms.text, a.font_normal, a.text_md]}>
117 <Trans>Anyone who follows me</Trans>
118 </Toggle.LabelText>
119 </Toggle.Item>
120 <Toggle.Item
121 label={_(msg`Only followers who I follow`)}
122 name="mutuals"
123 style={[a.flex_row, a.py_xs, a.gap_sm]}>
124 <Toggle.Radio />
125 <Toggle.LabelText style={[t.atoms.text, a.font_normal, a.text_md]}>
126 <Trans>Only followers who I follow</Trans>
127 </Toggle.LabelText>
128 </Toggle.Item>
129 <Toggle.Item
130 label={_(msg({context: 'enable for', message: `No one`}))}
131 name="none"
132 style={[a.flex_row, a.py_xs, a.gap_sm]}>
133 <Toggle.Radio />
134 <Toggle.LabelText style={[t.atoms.text, a.font_normal, a.text_md]}>
135 <Trans context="enable for">No one</Trans>
136 </Toggle.LabelText>
137 </Toggle.Item>
138 </View>
139 </Toggle.Group>
140 )
141}