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.

Handle birth dates as UTC, handle locale formatting (#2363)

* Enforce UTC for birthdate picker

* Handle locales

* Remove log

* Add a second snap point to the date input in case text is zoomed

* Guard against bad dates

* Log message

---------

Co-authored-by: Paul Frazee <pfrazee@gmail.com>

authored by

Eric Bailey
Paul Frazee
and committed by
GitHub
705f9b61 23c9c897

+31 -3
+17 -1
src/view/com/auth/create/Step2.tsx
··· 13 13 import {Trans, msg} from '@lingui/macro' 14 14 import {useLingui} from '@lingui/react' 15 15 import {useModalControls} from '#/state/modals' 16 + import {logger} from '#/logger' 17 + 18 + function sanitizeDate(date: Date): Date { 19 + if (!date || date.toString() === 'Invalid Date') { 20 + logger.error(`Create account: handled invalid date for birthDate`, { 21 + hasDate: !!date, 22 + }) 23 + return new Date() 24 + } 25 + return date 26 + } 16 27 17 28 /** STEP 2: Your account 18 29 * @field Invite code or waitlist ··· 37 48 const onPressWaitlist = React.useCallback(() => { 38 49 openModal({name: 'waitlist'}) 39 50 }, [openModal]) 51 + 52 + const birthDate = React.useMemo(() => { 53 + return sanitizeDate(uiState.birthDate) 54 + }, [uiState.birthDate]) 40 55 41 56 return ( 42 57 <View> ··· 122 137 <Trans>Your birth date</Trans> 123 138 </Text> 124 139 <DateInput 140 + handleAsUTC 125 141 testID="birthdayInput" 126 - value={uiState.birthDate} 142 + value={birthDate} 127 143 onChange={value => uiDispatch({type: 'set-birth-date', value})} 128 144 buttonType="default-light" 129 145 buttonStyle={[pal.border, styles.dateInputButton]}
+2 -1
src/view/com/modals/BirthDateSettings.tsx
··· 23 23 } from '#/state/queries/preferences' 24 24 import {logger} from '#/logger' 25 25 26 - export const snapPoints = ['50%'] 26 + export const snapPoints = ['50%', '90%'] 27 27 28 28 function Inner({preferences}: {preferences: UsePreferencesQueryResponse}) { 29 29 const pal = usePalette('default') ··· 63 63 64 64 <View> 65 65 <DateInput 66 + handleAsUTC 66 67 testID="birthdayInput" 67 68 value={date} 68 69 onChange={setDate}
+12 -1
src/view/com/util/forms/DateInput.tsx
··· 13 13 import {TypographyVariant} from 'lib/ThemeContext' 14 14 import {useTheme} from 'lib/ThemeContext' 15 15 import {usePalette} from 'lib/hooks/usePalette' 16 + import {getLocales} from 'expo-localization' 17 + 18 + const LOCALE = getLocales()[0] 16 19 17 20 interface Props { 18 21 testID?: string ··· 25 28 accessibilityLabel: string 26 29 accessibilityHint: string 27 30 accessibilityLabelledBy?: string 31 + handleAsUTC?: boolean 28 32 } 29 33 30 34 export function DateInput(props: Props) { ··· 32 36 const theme = useTheme() 33 37 const pal = usePalette('default') 34 38 39 + const formatter = React.useMemo(() => { 40 + return new Intl.DateTimeFormat(LOCALE.languageTag, { 41 + timeZone: props.handleAsUTC ? 'UTC' : undefined, 42 + }) 43 + }, [props.handleAsUTC]) 44 + 35 45 const onChangeInternal = useCallback( 36 46 (event: DateTimePickerEvent, date: Date | undefined) => { 37 47 setShow(false) ··· 64 74 <Text 65 75 type={props.buttonLabelType} 66 76 style={[pal.text, props.buttonLabelStyle]}> 67 - {props.value.toLocaleDateString()} 77 + {formatter.format(props.value)} 68 78 </Text> 69 79 </View> 70 80 </Button> ··· 73 83 <DateTimePicker 74 84 testID={props.testID ? `${props.testID}-datepicker` : undefined} 75 85 mode="date" 86 + timeZoneName={props.handleAsUTC ? 'Etc/UTC' : undefined} 76 87 display="spinner" 77 88 // @ts-ignore applies in iOS only -prf 78 89 themeVariant={theme.colorScheme}