From ee41aaa11232089cdb743ccc0b0ed9196f0cac12 Mon Sep 17 00:00:00 2001 From: MartinBraquet Date: Wed, 29 Oct 2025 17:51:12 +0100 Subject: [PATCH] Use WithPrivateUser --- web/components/notifications.tsx | 13 ++++++------- web/components/user/with-user.tsx | 10 ++++++++++ web/pages/settings.tsx | 13 ++++++------- 3 files changed, 22 insertions(+), 14 deletions(-) create mode 100644 web/components/user/with-user.tsx diff --git a/web/components/notifications.tsx b/web/components/notifications.tsx index b1c31481..b141c03c 100644 --- a/web/components/notifications.tsx +++ b/web/components/notifications.tsx @@ -8,15 +8,14 @@ import {useCallback} from "react"; import {debounce} from "lodash"; import {api} from "web/lib/api"; import {MultiSelectAnswers} from "web/components/answers/answer-compatibility-question-content"; -import {usePrivateUser} from "web/hooks/use-user"; import {PrivateUser} from "common/user"; -import {CompassLoadingIndicator} from "web/components/widgets/loading-indicator"; +import {WithPrivateUser} from "web/components/user/with-user"; -export const NotificationSettings = () => { - const privateUser = usePrivateUser() - if (!privateUser) return - return -} +export const NotificationSettings = () => ( + + {user => } + +) function LoadedNotificationSettings(props: { privateUser: PrivateUser, diff --git a/web/components/user/with-user.tsx b/web/components/user/with-user.tsx new file mode 100644 index 00000000..6279182d --- /dev/null +++ b/web/components/user/with-user.tsx @@ -0,0 +1,10 @@ +import {usePrivateUser} from "web/hooks/use-user"; +import {PrivateUser} from "common/user"; +import {CompassLoadingIndicator} from "web/components/widgets/loading-indicator"; + + +export function WithPrivateUser({children}: { children: (user: PrivateUser) => JSX.Element }) { + const privateUser = usePrivateUser() + if (!privateUser) return + return children(privateUser) +} \ No newline at end of file diff --git a/web/pages/settings.tsx b/web/pages/settings.tsx index 8bd22a37..750c04a3 100644 --- a/web/pages/settings.tsx +++ b/web/pages/settings.tsx @@ -3,7 +3,6 @@ import {NoSEO} from 'web/components/NoSEO' import {UncontrolledTabs} from 'web/components/layout/tabs' import {PageBase} from 'web/components/page-base' import {Title} from 'web/components/widgets/title' -import {usePrivateUser} from 'web/hooks/use-user' import {useRedirectIfSignedOut} from "web/hooks/use-redirect-if-signed-out"; import toast from "react-hot-toast"; import {deleteAccount} from "web/lib/util/delete"; @@ -13,7 +12,7 @@ import {getAuth, sendEmailVerification, sendPasswordResetEmail} from 'firebase/a import {auth} from "web/lib/firebase/users"; import {NotificationSettings} from "web/components/notifications"; import ThemeIcon from "web/components/theme-icon"; -import {CompassLoadingIndicator} from "web/components/widgets/loading-indicator"; +import {WithPrivateUser} from "web/components/user/with-user"; export default function NotificationsPage() { useRedirectIfSignedOut() @@ -32,11 +31,11 @@ export default function NotificationsPage() { ) } -export const GeneralSettings = () => { - const privateUser = usePrivateUser() - if (!privateUser) return - return -} +export const GeneralSettings = () => ( + + {user => } + +) const LoadedGeneralSettings = (props: { privateUser: PrivateUser,