mirror of https://git.lenooby09.tech/LeNooby09/social-app.git
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

at static-click 131 lines 3.9 kB view raw
1import React from 'react' 2import {View} from 'react-native' 3import {msg, Trans} from '@lingui/macro' 4import {useLingui} from '@lingui/react' 5 6import {cleanError} from '#/lib/strings/errors' 7import {logger} from '#/logger' 8import {isIOS, isWeb} from '#/platform/detection' 9import { 10 usePreferencesQuery, 11 UsePreferencesQueryResponse, 12 usePreferencesSetBirthDateMutation, 13} from '#/state/queries/preferences' 14import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' 15import {DateInput} from '#/view/com/util/forms/DateInput' 16import {atoms as a, useTheme} from '#/alf' 17import * as Dialog from '#/components/Dialog' 18import {Loader} from '#/components/Loader' 19import {Button, ButtonIcon, ButtonText} from '../Button' 20import {Text} from '../Typography' 21 22export function BirthDateSettingsDialog({ 23 control, 24}: { 25 control: Dialog.DialogControlProps 26}) { 27 const t = useTheme() 28 const {_} = useLingui() 29 const {isLoading, error, data: preferences} = usePreferencesQuery() 30 31 return ( 32 <Dialog.Outer control={control}> 33 <Dialog.Handle /> 34 <Dialog.ScrollableInner label={_(msg`My Birthday`)}> 35 <View style={[a.gap_sm, a.pb_lg]}> 36 <Text style={[a.text_2xl, a.font_bold]}> 37 <Trans>My Birthday</Trans> 38 </Text> 39 <Text style={[a.text_md, t.atoms.text_contrast_medium]}> 40 <Trans>This information is not shared with other users.</Trans> 41 </Text> 42 </View> 43 44 {isLoading ? ( 45 <Loader size="xl" /> 46 ) : error || !preferences ? ( 47 <ErrorMessage 48 message={ 49 error?.toString() || 50 _( 51 msg`We were unable to load your birth date preferences. Please try again.`, 52 ) 53 } 54 style={[a.rounded_sm]} 55 /> 56 ) : ( 57 <BirthdayInner control={control} preferences={preferences} /> 58 )} 59 60 <Dialog.Close /> 61 </Dialog.ScrollableInner> 62 </Dialog.Outer> 63 ) 64} 65 66function BirthdayInner({ 67 control, 68 preferences, 69}: { 70 control: Dialog.DialogControlProps 71 preferences: UsePreferencesQueryResponse 72}) { 73 const {_} = useLingui() 74 const [date, setDate] = React.useState(preferences.birthDate || new Date()) 75 const { 76 isPending, 77 isError, 78 error, 79 mutateAsync: setBirthDate, 80 } = usePreferencesSetBirthDateMutation() 81 const hasChanged = date !== preferences.birthDate 82 83 const onSave = React.useCallback(async () => { 84 try { 85 // skip if date is the same 86 if (hasChanged) { 87 await setBirthDate({birthDate: date}) 88 } 89 control.close() 90 } catch (e: any) { 91 logger.error(`setBirthDate failed`, {message: e.message}) 92 } 93 }, [date, setBirthDate, control, hasChanged]) 94 95 return ( 96 <View style={a.gap_lg} testID="birthDateSettingsDialog"> 97 <View style={isIOS && [a.w_full, a.align_center]}> 98 <DateInput 99 handleAsUTC 100 testID="birthdayInput" 101 value={date} 102 onChange={setDate} 103 buttonType="default-light" 104 buttonStyle={[a.rounded_sm]} 105 buttonLabelType="lg" 106 accessibilityLabel={_(msg`Birthday`)} 107 accessibilityHint={_(msg`Enter your birth date`)} 108 accessibilityLabelledBy="birthDate" 109 /> 110 </View> 111 112 {isError ? ( 113 <ErrorMessage message={cleanError(error)} style={[a.rounded_sm]} /> 114 ) : undefined} 115 116 <View style={isWeb && [a.flex_row, a.justify_end]}> 117 <Button 118 label={hasChanged ? _(msg`Save birthday`) : _(msg`Done`)} 119 size="large" 120 onPress={onSave} 121 variant="solid" 122 color="primary"> 123 <ButtonText> 124 {hasChanged ? <Trans>Save</Trans> : <Trans>Done</Trans>} 125 </ButtonText> 126 {isPending && <ButtonIcon icon={Loader} />} 127 </Button> 128 </View> 129 </View> 130 ) 131}