From 8ac5144a584450f037771de4da775d545b70ffa3 Mon Sep 17 00:00:00 2001 From: Eric Bailey Date: Tue, 19 Mar 2024 09:57:14 -0500 Subject: [PATCH] Bday modal tweaks (#3252) * Smol tweaks to bday dialog * Juse use existing DateInput for now * Remove unused code * Remove passed-in prefs * Adjust load state * Revert "Adjust load state" This reverts commit 802459fd044b380ccc4f96432af416996219a0de. * Fix type error --- src/components/dialogs/BirthDateSettings.tsx | 74 +++++++++++--------- src/screens/Moderation/index.tsx | 5 +- src/view/screens/Settings/index.tsx | 11 +-- 3 files changed, 44 insertions(+), 46 deletions(-) diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx index 62c95c78..4a3e96e5 100644 --- a/src/components/dialogs/BirthDateSettings.tsx +++ b/src/components/dialogs/BirthDateSettings.tsx @@ -1,48 +1,64 @@ import React from 'react' import {useLingui} from '@lingui/react' import {Trans, msg} from '@lingui/macro' +import {View} from 'react-native' import * as Dialog from '#/components/Dialog' import {Text} from '../Typography' import {DateInput} from '#/view/com/util/forms/DateInput' import {logger} from '#/logger' import { + usePreferencesQuery, usePreferencesSetBirthDateMutation, UsePreferencesQueryResponse, } from '#/state/queries/preferences' -import {Button, ButtonText} from '../Button' +import {Button, ButtonIcon, ButtonText} from '../Button' 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' +import {Loader} from '#/components/Loader' export function BirthDateSettingsDialog({ control, - preferences, }: { control: Dialog.DialogControlProps - preferences: UsePreferencesQueryResponse | undefined }) { + const t = useTheme() const {_} = useLingui() - const {isPending, isError, error, mutateAsync} = - usePreferencesSetBirthDateMutation() + const {isLoading, error, data: preferences} = usePreferencesQuery() return ( + - {preferences && !isPending ? ( - + + My Birthday + + + This information is not shared with other users. + + + + {isLoading ? ( + + ) : error || !preferences ? ( + ) : ( - + )} + + ) @@ -51,20 +67,18 @@ export function BirthDateSettingsDialog({ 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 { + isPending, + isError, + error, + mutateAsync: setBirthDate, + } = usePreferencesSetBirthDateMutation() const hasChanged = date !== preferences.birthDate const onSave = React.useCallback(async () => { @@ -74,21 +88,13 @@ function BirthdayInner({ await setBirthDate({birthDate: date}) } control.close() - } catch (e) { - logger.error(`setBirthDate failed`, {message: e}) + } catch (e: any) { + logger.error(`setBirthDate failed`, {message: e.message}) } }, [date, setBirthDate, control, hasChanged]) return ( - - - My Birthday - - - This information is not shared with other users. - - + {isError ? ( ) : undefined} @@ -110,13 +117,14 @@ function BirthdayInner({ diff --git a/src/screens/Moderation/index.tsx b/src/screens/Moderation/index.tsx index 26fa9ec7..d0bfaead 100644 --- a/src/screens/Moderation/index.tsx +++ b/src/screens/Moderation/index.tsx @@ -308,10 +308,7 @@ export function ModerationScreenInner({ - + )} - +