diff options
Diffstat (limited to 'src/screens/Messages/Settings.tsx')
-rw-r--r-- | src/screens/Messages/Settings.tsx | 70 |
1 files changed, 70 insertions, 0 deletions
diff --git a/src/screens/Messages/Settings.tsx b/src/screens/Messages/Settings.tsx new file mode 100644 index 000000000..9faab4130 --- /dev/null +++ b/src/screens/Messages/Settings.tsx @@ -0,0 +1,70 @@ +import React, {useCallback} from 'react' +import {View} from 'react-native' +import {AppBskyActorDefs} from '@atproto/api' +import {msg, Trans} from '@lingui/macro' +import {useLingui} from '@lingui/react' +import {NativeStackScreenProps} from '@react-navigation/native-stack' +import {UseQueryResult} from '@tanstack/react-query' + +import {CommonNavigatorParams} from '#/lib/routes/types' +import {useGate} from '#/lib/statsig/statsig' +import {useUpdateActorDeclaration} from '#/state/queries/messages/actor-declaration' +import {useProfileQuery} from '#/state/queries/profile' +import {useSession} from '#/state/session' +import * as Toast from '#/view/com/util/Toast' +import {ViewHeader} from '#/view/com/util/ViewHeader' +import {CenteredView} from '#/view/com/util/Views' +import {atoms as a} from '#/alf' +import {RadioGroup} from '#/components/RadioGroup' +import {Text} from '#/components/Typography' +import {ClipClopGate} from './gate' + +type AllowIncoming = 'all' | 'none' | 'following' + +type Props = NativeStackScreenProps<CommonNavigatorParams, 'MessagesSettings'> +export function MessagesSettingsScreen({}: Props) { + const {_} = useLingui() + const {currentAccount} = useSession() + const {data: profile} = useProfileQuery({ + did: currentAccount!.did, + }) as UseQueryResult<AppBskyActorDefs.ProfileViewDetailed, Error> + + const {mutate: updateDeclaration} = useUpdateActorDeclaration({ + onError: () => { + Toast.show(_(msg`Failed to update settings`)) + }, + }) + + const onSelectItem = useCallback( + (key: string) => { + updateDeclaration(key as AllowIncoming) + }, + [updateDeclaration], + ) + + const gate = useGate() + if (!gate('dms')) return <ClipClopGate /> + + return ( + <CenteredView sideBorders> + <ViewHeader title={_(msg`Settings`)} showOnDesktop showBorder /> + <View style={[a.px_md, a.py_lg, a.gap_md]}> + <Text style={[a.text_xl, a.font_bold, a.px_sm]}> + <Trans>Allow messages from</Trans> + </Text> + <RadioGroup<AllowIncoming> + value={ + (profile?.associated?.chat?.allowIncoming as AllowIncoming) ?? + 'following' + } + items={[ + {label: _(msg`Everyone`), value: 'all'}, + {label: _(msg`Follows only`), value: 'following'}, + {label: _(msg`No one`), value: 'none'}, + ]} + onSelect={onSelectItem} + /> + </View> + </CenteredView> + ) +} |