From 577091d44d15680d0c14f7d4571d630bf558a74d Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 15 Mar 2024 15:45:58 +0000 Subject: ALF the birthday modal and remove legacy one --- src/components/dialogs/BirthdaySettings.tsx | 122 ++++++++++++++++++++++++++++ 1 file changed, 122 insertions(+) create mode 100644 src/components/dialogs/BirthdaySettings.tsx (limited to 'src/components/dialogs') diff --git a/src/components/dialogs/BirthdaySettings.tsx b/src/components/dialogs/BirthdaySettings.tsx new file mode 100644 index 000000000..00f6ff57e --- /dev/null +++ b/src/components/dialogs/BirthdaySettings.tsx @@ -0,0 +1,122 @@ +import React from 'react' +import {useLingui} from '@lingui/react' +import {Trans, msg} from '@lingui/macro' + +import * as Dialog from '#/components/Dialog' +import {Text} from '../Typography' +import {DateInput} from '#/view/com/util/forms/DateInput' +import {logger} from '#/logger' +import { + usePreferencesSetBirthDateMutation, + UsePreferencesQueryResponse, +} from '#/state/queries/preferences' +import {Button, ButtonText} from '../Button' +import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' +import {cleanError} from '#/lib/strings/errors' +import {ActivityIndicator, View} from 'react-native' + +export function BirthdaySettingsDialog({ + control, + preferences, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse | undefined +}) { + const {_} = useLingui() + const {isPending, isError, error, mutateAsync} = + usePreferencesSetBirthDateMutation() + + return ( + + + + {preferences && !isPending ? ( + + ) : ( + + )} + + + ) +} + +function BirthdayInner({ + control, + preferences, + isError, + error, + setBirthDate, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse + isError: boolean + error: unknown + setBirthDate: (args: {birthDate: Date}) => Promise +}) { + const {_} = useLingui() + const [date, setDate] = React.useState(preferences.birthDate || new Date()) + const t = useTheme() + const {gtMobile} = useBreakpoints() + + const hasChanged = date !== preferences.birthDate + + const onSave = React.useCallback(async () => { + try { + // skip if date is the same + if (hasChanged) { + await setBirthDate({birthDate: date}) + } + control.close() + } catch (e) { + logger.error(`setBirthDate failed`, {message: e}) + } + }, [date, setBirthDate, control, hasChanged]) + + return ( + + + + My Birthday + + + This information is not shared with other users. + + + + {isError ? ( + + ) : undefined} + + + + + + ) +} -- cgit 1.4.1 From 884f37c34900559d8e3a881dd8fa2ab781eafbdb Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 15 Mar 2024 15:50:54 +0000 Subject: rename BirthdaySettings -> BirthDateSettings + remove legacy modal --- src/components/dialogs/BirthDateSettings.tsx | 122 ++++++++++++++++++ src/components/dialogs/BirthdaySettings.tsx | 122 ------------------ src/view/com/modals/BirthDateSettings.tsx | 151 ----------------------- src/view/com/modals/ContentFilteringSettings.tsx | 4 +- src/view/screens/Settings/index.tsx | 4 +- 5 files changed, 126 insertions(+), 277 deletions(-) create mode 100644 src/components/dialogs/BirthDateSettings.tsx delete mode 100644 src/components/dialogs/BirthdaySettings.tsx delete mode 100644 src/view/com/modals/BirthDateSettings.tsx (limited to 'src/components/dialogs') diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx new file mode 100644 index 000000000..47d7faa0c --- /dev/null +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -0,0 +1,122 @@ +import React from 'react' +import {useLingui} from '@lingui/react' +import {Trans, msg} from '@lingui/macro' + +import * as Dialog from '#/components/Dialog' +import {Text} from '../Typography' +import {DateInput} from '#/view/com/util/forms/DateInput' +import {logger} from '#/logger' +import { + usePreferencesSetBirthDateMutation, + UsePreferencesQueryResponse, +} from '#/state/queries/preferences' +import {Button, ButtonText} from '../Button' +import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' +import {cleanError} from '#/lib/strings/errors' +import {ActivityIndicator, View} from 'react-native' + +export function BirthDateSettingsDialog({ + control, + preferences, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse | undefined +}) { + const {_} = useLingui() + const {isPending, isError, error, mutateAsync} = + usePreferencesSetBirthDateMutation() + + return ( + + + + {preferences && !isPending ? ( + + ) : ( + + )} + + + ) +} + +function BirthdayInner({ + control, + preferences, + isError, + error, + setBirthDate, +}: { + control: Dialog.DialogControlProps + preferences: UsePreferencesQueryResponse + isError: boolean + error: unknown + setBirthDate: (args: {birthDate: Date}) => Promise +}) { + const {_} = useLingui() + const [date, setDate] = React.useState(preferences.birthDate || new Date()) + const t = useTheme() + const {gtMobile} = useBreakpoints() + + const hasChanged = date !== preferences.birthDate + + const onSave = React.useCallback(async () => { + try { + // skip if date is the same + if (hasChanged) { + await setBirthDate({birthDate: date}) + } + control.close() + } catch (e) { + logger.error(`setBirthDate failed`, {message: e}) + } + }, [date, setBirthDate, control, hasChanged]) + + return ( + + + + My Birthday + + + This information is not shared with other users. + + + + {isError ? ( + + ) : undefined} + + + + + + ) +} diff --git a/src/components/dialogs/BirthdaySettings.tsx b/src/components/dialogs/BirthdaySettings.tsx deleted file mode 100644 index 00f6ff57e..000000000 --- a/src/components/dialogs/BirthdaySettings.tsx +++ /dev/null @@ -1,122 +0,0 @@ -import React from 'react' -import {useLingui} from '@lingui/react' -import {Trans, msg} from '@lingui/macro' - -import * as Dialog from '#/components/Dialog' -import {Text} from '../Typography' -import {DateInput} from '#/view/com/util/forms/DateInput' -import {logger} from '#/logger' -import { - usePreferencesSetBirthDateMutation, - UsePreferencesQueryResponse, -} from '#/state/queries/preferences' -import {Button, ButtonText} from '../Button' -import {atoms as a, useBreakpoints, useTheme} from '#/alf' -import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' -import {cleanError} from '#/lib/strings/errors' -import {ActivityIndicator, View} from 'react-native' - -export function BirthdaySettingsDialog({ - control, - preferences, -}: { - control: Dialog.DialogControlProps - preferences: UsePreferencesQueryResponse | undefined -}) { - const {_} = useLingui() - const {isPending, isError, error, mutateAsync} = - usePreferencesSetBirthDateMutation() - - return ( - - - - {preferences && !isPending ? ( - - ) : ( - - )} - - - ) -} - -function BirthdayInner({ - control, - preferences, - isError, - error, - setBirthDate, -}: { - control: Dialog.DialogControlProps - preferences: UsePreferencesQueryResponse - isError: boolean - error: unknown - setBirthDate: (args: {birthDate: Date}) => Promise -}) { - const {_} = useLingui() - const [date, setDate] = React.useState(preferences.birthDate || new Date()) - const t = useTheme() - const {gtMobile} = useBreakpoints() - - const hasChanged = date !== preferences.birthDate - - const onSave = React.useCallback(async () => { - try { - // skip if date is the same - if (hasChanged) { - await setBirthDate({birthDate: date}) - } - control.close() - } catch (e) { - logger.error(`setBirthDate failed`, {message: e}) - } - }, [date, setBirthDate, control, hasChanged]) - - return ( - - - - My Birthday - - - This information is not shared with other users. - - - - {isError ? ( - - ) : undefined} - - - - - - ) -} diff --git a/src/view/com/modals/BirthDateSettings.tsx b/src/view/com/modals/BirthDateSettings.tsx deleted file mode 100644 index 1cab95989..000000000 --- a/src/view/com/modals/BirthDateSettings.tsx +++ /dev/null @@ -1,151 +0,0 @@ -import React, {useState} from 'react' -import { - ActivityIndicator, - StyleSheet, - TouchableOpacity, - View, -} from 'react-native' -import {Text} from '../util/text/Text' -import {DateInput} from '../util/forms/DateInput' -import {ErrorMessage} from '../util/error/ErrorMessage' -import {s, colors} from 'lib/styles' -import {usePalette} from 'lib/hooks/usePalette' -import {isWeb} from 'platform/detection' -import {useWebMediaQueries} from 'lib/hooks/useWebMediaQueries' -import {cleanError} from 'lib/strings/errors' -import {Trans, msg} from '@lingui/macro' -import {useLingui} from '@lingui/react' -import {useModalControls} from '#/state/modals' -import { - usePreferencesQuery, - usePreferencesSetBirthDateMutation, - UsePreferencesQueryResponse, -} from '#/state/queries/preferences' -import {logger} from '#/logger' - -export const snapPoints = ['50%', '90%'] - -function Inner({preferences}: {preferences: UsePreferencesQueryResponse}) { - const pal = usePalette('default') - const {isMobile} = useWebMediaQueries() - const {_} = useLingui() - const { - isPending, - isError, - error, - mutateAsync: setBirthDate, - } = usePreferencesSetBirthDateMutation() - const [date, setDate] = useState(preferences.birthDate || new Date()) - const {closeModal} = useModalControls() - - const onSave = React.useCallback(async () => { - try { - await setBirthDate({birthDate: date}) - closeModal() - } catch (e) { - logger.error(`setBirthDate failed`, {message: e}) - } - }, [date, setBirthDate, closeModal]) - - return ( - - - - My Birthday - - - - - This information is not shared with other users. - - - - - - - {isError ? ( - - ) : undefined} - - - {isPending ? ( - - - - ) : ( - - - Save - - - )} - - - ) -} - -export function Component({}: {}) { - const {data: preferences} = usePreferencesQuery() - - return !preferences ? ( - - ) : ( - - ) -} - -const styles = StyleSheet.create({ - container: { - flex: 1, - paddingBottom: isWeb ? 0 : 40, - }, - titleSection: { - paddingTop: isWeb ? 0 : 4, - paddingBottom: isWeb ? 14 : 10, - }, - title: { - textAlign: 'center', - fontWeight: '600', - marginBottom: 5, - }, - error: { - borderRadius: 6, - marginTop: 10, - }, - dateInputButton: { - borderWidth: 1, - borderRadius: 6, - paddingVertical: 14, - }, - btn: { - flexDirection: 'row', - alignItems: 'center', - justifyContent: 'center', - borderRadius: 32, - padding: 14, - backgroundColor: colors.blue3, - }, - btnContainer: { - paddingTop: 20, - paddingHorizontal: 20, - }, -}) diff --git a/src/view/com/modals/ContentFilteringSettings.tsx b/src/view/com/modals/ContentFilteringSettings.tsx index 56bb9c837..3c7edcf0d 100644 --- a/src/view/com/modals/ContentFilteringSettings.tsx +++ b/src/view/com/modals/ContentFilteringSettings.tsx @@ -25,7 +25,7 @@ import { UsePreferencesQueryResponse, } from '#/state/queries/preferences' import {useDialogControl} from '#/components/Dialog' -import {BirthdaySettingsDialog} from '#/components/dialogs/BirthdaySettings' +import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings' export const snapPoints = ['90%'] @@ -137,7 +137,7 @@ function AdultContentEnabledPref() { return ( - diff --git a/src/view/screens/Settings/index.tsx b/src/view/screens/Settings/index.tsx index 4ea2a6701..3b5e190c1 100644 --- a/src/view/screens/Settings/index.tsx +++ b/src/view/screens/Settings/index.tsx @@ -71,7 +71,7 @@ import {SelectableBtn} from 'view/com/util/forms/SelectableBtn' import {AccountDropdownBtn} from 'view/com/util/AccountDropdownBtn' import {SimpleViewHeader} from 'view/com/util/SimpleViewHeader' import {ExportCarDialog} from './ExportCarDialog' -import {BirthdaySettingsDialog} from '#/components/dialogs/BirthdaySettings' +import {BirthDateSettingsDialog} from '#/components/dialogs/BirthDateSettings' function SettingsAccountCard({account}: {account: SessionAccount}) { const pal = usePalette('default') @@ -291,7 +291,7 @@ export function SettingsScreen({}: Props) { return ( - -- cgit 1.4.1 From 502df521c1187bbd71228ec03fdd9a9ce6f0ead0 Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 15 Mar 2024 16:03:08 +0000 Subject: center date input --- src/components/dialogs/BirthDateSettings.tsx | 26 ++++++++++++++------------ 1 file changed, 14 insertions(+), 12 deletions(-) (limited to 'src/components/dialogs') diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index 47d7faa0c..3ae8fa6cd 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -89,18 +89,20 @@ function BirthdayInner({ This information is not shared with other users. - + + + {isError ? ( ) : undefined} -- cgit 1.4.1 From 58ac22c45b9177e60e73d00d8ce0e1734c3692da Mon Sep 17 00:00:00 2001 From: Samuel Newman Date: Fri, 15 Mar 2024 16:21:15 +0000 Subject: make alignment platform specific rather than size specific --- src/components/dialogs/BirthDateSettings.tsx | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) (limited to 'src/components/dialogs') diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index 3ae8fa6cd..5fe7b7bcc 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -11,10 +11,11 @@ import { UsePreferencesQueryResponse, } from '#/state/queries/preferences' import {Button, ButtonText} from '../Button' -import {atoms as a, useBreakpoints, useTheme} from '#/alf' +import {atoms as a, useTheme} from '#/alf' import {ErrorMessage} from '#/view/com/util/error/ErrorMessage' import {cleanError} from '#/lib/strings/errors' import {ActivityIndicator, View} from 'react-native' +import {isIOS, isWeb} from '#/platform/detection' export function BirthDateSettingsDialog({ control, @@ -63,7 +64,6 @@ function BirthdayInner({ const {_} = useLingui() const [date, setDate] = React.useState(preferences.birthDate || new Date()) const t = useTheme() - const {gtMobile} = useBreakpoints() const hasChanged = date !== preferences.birthDate @@ -80,7 +80,7 @@ function BirthdayInner({ }, [date, setBirthDate, control, hasChanged]) return ( - + My Birthday @@ -89,7 +89,7 @@ function BirthdayInner({ This information is not shared with other users. - + ) : undefined} - +