From 884f37c34900559d8e3a881dd8fa2ab781eafbdb Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Fri, 15 Mar 2024 15:50:54 +0000
Subject: rename BirthdaySettings -> BirthDateSettings + remove legacy modal

---
 src/components/dialogs/BirthDateSettings.tsx | 122 +++++++++++++++++++++++++++
 1 file changed, 122 insertions(+)
 create mode 100644 src/components/dialogs/BirthDateSettings.tsx

(limited to 'src/components/dialogs/BirthDateSettings.tsx')

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 (
+    <Dialog.Outer control={control}>
+      <Dialog.Handle />
+      <Dialog.Inner label={_(msg`My Birthday`)}>
+        {preferences && !isPending ? (
+          <BirthdayInner
+            control={control}
+            preferences={preferences}
+            isError={isError}
+            error={error}
+            setBirthDate={mutateAsync}
+          />
+        ) : (
+          <ActivityIndicator size="large" style={a.my_5xl} />
+        )}
+      </Dialog.Inner>
+    </Dialog.Outer>
+  )
+}
+
+function BirthdayInner({
+  control,
+  preferences,
+  isError,
+  error,
+  setBirthDate,
+}: {
+  control: Dialog.DialogControlProps
+  preferences: UsePreferencesQueryResponse
+  isError: boolean
+  error: unknown
+  setBirthDate: (args: {birthDate: Date}) => Promise<unknown>
+}) {
+  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 (
+    <View style={a.gap_lg}>
+      <View style={[a.gap_sm]}>
+        <Text style={[a.text_2xl, a.font_bold]}>
+          <Trans>My Birthday</Trans>
+        </Text>
+        <Text style={t.atoms.text_contrast_medium}>
+          <Trans>This information is not shared with other users.</Trans>
+        </Text>
+      </View>
+      <DateInput
+        handleAsUTC
+        testID="birthdayInput"
+        value={date}
+        onChange={setDate}
+        buttonType="default-light"
+        buttonStyle={[a.rounded_sm]}
+        buttonLabelType="lg"
+        accessibilityLabel={_(msg`Birthday`)}
+        accessibilityHint={_(msg`Enter your birth date`)}
+        accessibilityLabelledBy="birthDate"
+      />
+      {isError ? (
+        <ErrorMessage message={cleanError(error)} style={[a.rounded_sm]} />
+      ) : undefined}
+
+      <View style={gtMobile && [a.flex_row, a.justify_end]}>
+        <Button
+          label={hasChanged ? _(msg`Save birthday`) : _(msg`Done`)}
+          size={gtMobile ? 'small' : 'medium'}
+          onPress={onSave}
+          variant="solid"
+          color="primary">
+          <ButtonText>
+            {hasChanged ? <Trans>Save</Trans> : <Trans>Done</Trans>}
+          </ButtonText>
+        </Button>
+      </View>
+    </View>
+  )
+}
-- 
cgit 1.4.1


From 502df521c1187bbd71228ec03fdd9a9ce6f0ead0 Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
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/BirthDateSettings.tsx')

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({
           <Trans>This information is not shared with other users.</Trans>
         </Text>
       </View>
-      <DateInput
-        handleAsUTC
-        testID="birthdayInput"
-        value={date}
-        onChange={setDate}
-        buttonType="default-light"
-        buttonStyle={[a.rounded_sm]}
-        buttonLabelType="lg"
-        accessibilityLabel={_(msg`Birthday`)}
-        accessibilityHint={_(msg`Enter your birth date`)}
-        accessibilityLabelledBy="birthDate"
-      />
+      <View style={[a.w_full, a.align_center]}>
+        <DateInput
+          handleAsUTC
+          testID="birthdayInput"
+          value={date}
+          onChange={setDate}
+          buttonType="default-light"
+          buttonStyle={[a.rounded_sm]}
+          buttonLabelType="lg"
+          accessibilityLabel={_(msg`Birthday`)}
+          accessibilityHint={_(msg`Enter your birth date`)}
+          accessibilityLabelledBy="birthDate"
+        />
+      </View>
       {isError ? (
         <ErrorMessage message={cleanError(error)} style={[a.rounded_sm]} />
       ) : undefined}
-- 
cgit 1.4.1


From 58ac22c45b9177e60e73d00d8ce0e1734c3692da Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
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/BirthDateSettings.tsx')

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 (
-    <View style={a.gap_lg}>
+    <View style={a.gap_lg} testID="birthDateSettingsDialog">
       <View style={[a.gap_sm]}>
         <Text style={[a.text_2xl, a.font_bold]}>
           <Trans>My Birthday</Trans>
@@ -89,7 +89,7 @@ function BirthdayInner({
           <Trans>This information is not shared with other users.</Trans>
         </Text>
       </View>
-      <View style={[a.w_full, a.align_center]}>
+      <View style={isIOS && [a.w_full, a.align_center]}>
         <DateInput
           handleAsUTC
           testID="birthdayInput"
@@ -107,10 +107,10 @@ function BirthdayInner({
         <ErrorMessage message={cleanError(error)} style={[a.rounded_sm]} />
       ) : undefined}
 
-      <View style={gtMobile && [a.flex_row, a.justify_end]}>
+      <View style={isWeb && [a.flex_row, a.justify_end]}>
         <Button
           label={hasChanged ? _(msg`Save birthday`) : _(msg`Done`)}
-          size={gtMobile ? 'small' : 'medium'}
+          size={isWeb ? 'small' : 'medium'}
           onPress={onSave}
           variant="solid"
           color="primary">
-- 
cgit 1.4.1


From 38ea041136a5e8d1c7950d309e0580b051525cd9 Mon Sep 17 00:00:00 2001
From: Samuel Newman <mozzius@protonmail.com>
Date: Fri, 15 Mar 2024 16:22:09 +0000
Subject: change to scrollable inner

---
 src/components/dialogs/BirthDateSettings.tsx | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

(limited to 'src/components/dialogs/BirthDateSettings.tsx')

diff --git a/src/components/dialogs/BirthDateSettings.tsx b/src/components/dialogs/BirthDateSettings.tsx
index 5fe7b7bcc..62c95c78d 100644
--- a/src/components/dialogs/BirthDateSettings.tsx
+++ b/src/components/dialogs/BirthDateSettings.tsx
@@ -31,7 +31,7 @@ export function BirthDateSettingsDialog({
   return (
     <Dialog.Outer control={control}>
       <Dialog.Handle />
-      <Dialog.Inner label={_(msg`My Birthday`)}>
+      <Dialog.ScrollableInner label={_(msg`My Birthday`)}>
         {preferences && !isPending ? (
           <BirthdayInner
             control={control}
@@ -43,7 +43,7 @@ export function BirthDateSettingsDialog({
         ) : (
           <ActivityIndicator size="large" style={a.my_5xl} />
         )}
-      </Dialog.Inner>
+      </Dialog.ScrollableInner>
     </Dialog.Outer>
   )
 }
-- 
cgit 1.4.1

