From 468cc5e1bb82dd00c56188f466df1f53ef579150 Mon Sep 17 00:00:00 2001 From: satooru65536 Date: Tue, 28 May 2024 18:10:38 +0900 Subject: [PATCH 1/3] =?UTF-8?q?fix:=20CurrentUser=E5=91=A8=E3=82=8A?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/BaseLayout.tsx | 6 +++--- src/stores/{userAtom.ts => currentUserAtom.ts} | 11 +++++------ src/types/user.ts | 10 +--------- 3 files changed, 9 insertions(+), 18 deletions(-) rename src/stores/{userAtom.ts => currentUserAtom.ts} (74%) diff --git a/src/layouts/BaseLayout.tsx b/src/layouts/BaseLayout.tsx index dbe70ad..d118f36 100644 --- a/src/layouts/BaseLayout.tsx +++ b/src/layouts/BaseLayout.tsx @@ -7,7 +7,7 @@ import 'the-new-css-reset/css/reset.css'; import { createGlobalStyle } from 'styled-components'; import LoginPage from '@/components/pages/login'; import Header from '@/components/shared/Header'; -import { userAtomLoadable } from '@/stores/userAtom'; +import { currentUserAtomLoadable } from '@/stores/userAtom'; import { theme } from '@/utils/theme'; const { Header: HeaderContainer, Content } = Layout; @@ -26,7 +26,7 @@ const GlobalStyle = createGlobalStyle` `; const BaseLayout = (): ReactElement => { - const user = useAtomValue(userAtomLoadable); + const user = useAtomValue(currentUserAtomLoadable); if (user.state === 'hasError') throw Error('Failed to fetch user data'); @@ -44,7 +44,7 @@ const BaseLayout = (): ReactElement => { )} - {user.state === 'hasData' && (user.data.signined ? : )} + {user.state === 'hasData' && (user.data == null ? : )} diff --git a/src/stores/userAtom.ts b/src/stores/currentUserAtom.ts similarity index 74% rename from src/stores/userAtom.ts rename to src/stores/currentUserAtom.ts index c9b4183..367a05b 100644 --- a/src/stores/userAtom.ts +++ b/src/stores/currentUserAtom.ts @@ -1,13 +1,12 @@ import { atom } from 'jotai'; import { loadable } from 'jotai/utils'; -import { type SigninedUser } from '@/types/user'; +import { type CurrentUser } from '@/types/user'; import { waitMs } from '@/utils/promise'; -const fetchUser = async (): Promise> => { +const fetchCurrentUser = async (): Promise => { await waitMs(2000); - const user: SigninedUser = { - signined: true, + const user: CurrentUser = { id: '0000-0000-0000-0000', firstName: '智', lastName: '佐藤', @@ -38,5 +37,5 @@ const fetchUser = async (): Promise> => { return user; }; -const userAtom = atom(async () => await fetchUser()); -export const userAtomLoadable = loadable(userAtom); +const currentUserAtomAtom = atom(async () => await fetchCurrentUser()); +export const currentUserAtomLoadable = loadable(currentUserAtomAtom); diff --git a/src/types/user.ts b/src/types/user.ts index cc43329..58c1dd4 100644 --- a/src/types/user.ts +++ b/src/types/user.ts @@ -54,12 +54,4 @@ export type User = UserBase & (ActiveUserProps | OBOGMemberProps | ExternalMember) & (WithPrivate extends true ? PrivateProps : Record); -type IsSigninedUser = { - signined: true; -} & User; - -interface IsNotSigninedUser { - signined: false; -} - -export type SigninedUser = T extends true ? IsSigninedUser : IsNotSigninedUser; +export type CurrentUser = User | null; From 11387df1aa7b9108ec5a32033dd031d10a5a753b Mon Sep 17 00:00:00 2001 From: satooru65536 Date: Tue, 28 May 2024 18:17:31 +0900 Subject: [PATCH 2/3] =?UTF-8?q?fix:=20=E3=83=95=E3=82=A1=E3=82=A4=E3=83=AB?= =?UTF-8?q?=E3=83=91=E3=82=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/BaseLayout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/BaseLayout.tsx b/src/layouts/BaseLayout.tsx index d118f36..cc1e956 100644 --- a/src/layouts/BaseLayout.tsx +++ b/src/layouts/BaseLayout.tsx @@ -7,7 +7,7 @@ import 'the-new-css-reset/css/reset.css'; import { createGlobalStyle } from 'styled-components'; import LoginPage from '@/components/pages/login'; import Header from '@/components/shared/Header'; -import { currentUserAtomLoadable } from '@/stores/userAtom'; +import { currentUserAtomLoadable } from '@/stores/currentUserAtom'; import { theme } from '@/utils/theme'; const { Header: HeaderContainer, Content } = Layout; From 6248ec2b2711d43bdac51ff8d9d3e7f767943532 Mon Sep 17 00:00:00 2001 From: satooru65536 Date: Tue, 28 May 2024 18:20:01 +0900 Subject: [PATCH 3/3] =?UTF-8?q?fix:=20=E3=83=AD=E3=82=B0=E3=82=A4=E3=83=B3?= =?UTF-8?q?=E6=B8=88=E3=81=AE=E5=A0=B4=E5=90=88=E3=81=AB=E3=83=AD=E3=82=B0?= =?UTF-8?q?=E3=82=A4=E3=83=B3=E3=83=9C=E3=82=BF=E3=83=B3=E3=81=8C=E5=87=BA?= =?UTF-8?q?=E3=82=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- src/layouts/BaseLayout.tsx | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/layouts/BaseLayout.tsx b/src/layouts/BaseLayout.tsx index cc1e956..3343a9d 100644 --- a/src/layouts/BaseLayout.tsx +++ b/src/layouts/BaseLayout.tsx @@ -44,7 +44,7 @@ const BaseLayout = (): ReactElement => { )} - {user.state === 'hasData' && (user.data == null ? : )} + {user.state === 'hasData' && (user.data != null ? : )}