From bf4866ece1da4f782513e6fce4d492a92e9dbb48 Mon Sep 17 00:00:00 2001 From: solufa Date: Fri, 21 Jun 2024 21:46:35 +0900 Subject: [PATCH] refactor: use render prop --- client/components/Auth/AuthLoader.tsx | 3 -- client/layouts/Layout.tsx | 6 +-- client/pages/console/index.page.tsx | 73 ++++++++++++++------------- 3 files changed, 40 insertions(+), 42 deletions(-) diff --git a/client/components/Auth/AuthLoader.tsx b/client/components/Auth/AuthLoader.tsx index b8fc868..17ba2eb 100644 --- a/client/components/Auth/AuthLoader.tsx +++ b/client/components/Auth/AuthLoader.tsx @@ -52,11 +52,8 @@ export const AuthLoader = () => { async (data) => { switch (data.payload.event) { case 'customOAuthState': - break; case 'signInWithRedirect': - break; case 'signInWithRedirect_failure': - break; case 'tokenRefresh': break; case 'signedOut': diff --git a/client/layouts/Layout.tsx b/client/layouts/Layout.tsx index 6cf4057..2fc81ad 100644 --- a/client/layouts/Layout.tsx +++ b/client/layouts/Layout.tsx @@ -9,7 +9,7 @@ import { useRouter } from 'next/router'; import React from 'react'; import { pagesPath } from 'utils/$path'; -export const Layout = (props: { content: (user: UserEntity) => React.ReactNode }) => { +export const Layout = (props: { render: (user: UserEntity) => React.ReactNode }) => { const router = useRouter(); const { user } = useUser(); const { loadingElm } = useLoading(); @@ -18,7 +18,7 @@ export const Layout = (props: { content: (user: UserEntity) => React.ReactNode } if (!user.inited) { return ; - } else if (!user.data) { + } else if (user.data === null) { void router.replace(pagesPath.$url()); return ; @@ -27,7 +27,7 @@ export const Layout = (props: { content: (user: UserEntity) => React.ReactNode } return (
- {props.content(user.data)} + {props.render(user.data)} {loadingElm} {alertElm} {confirmElm} diff --git a/client/pages/console/index.page.tsx b/client/pages/console/index.page.tsx index 9b0fc13..4be584d 100644 --- a/client/pages/console/index.page.tsx +++ b/client/pages/console/index.page.tsx @@ -1,4 +1,5 @@ import type { TaskEntity } from 'api/@types/task'; +import type { UserEntity } from 'api/@types/user'; import { Loading } from 'components/Loading/Loading'; import { Layout } from 'layouts/Layout'; import type { FormEvent } from 'react'; @@ -7,7 +8,7 @@ import { apiClient } from 'utils/apiClient'; import { returnNull } from 'utils/returnNull'; import styles from './index.module.css'; -const Console = () => { +const Main = (props: { user: UserEntity }) => { const [tasks, setTasks] = useState(); const [label, setLabel] = useState(''); const fetchTasks = async () => { @@ -41,44 +42,44 @@ const Console = () => { if (!tasks) return ; return ( - ( -
-
Todo list of {user.name}
-
-
-
-
- setLabel(e.target.value)} - /> - -
-
+
+
Todo list of {props.user.name}
+
+
+
+
+ setLabel(e.target.value)} + /> +
- {tasks.map((task) => ( -
-
- toggleDone(task)} /> - {task.label} - deleteTask(task)} - /> -
-
- ))} -
+
- )} - /> + {tasks.map((task) => ( +
+
+ toggleDone(task)} /> + {task.label} + deleteTask(task)} + /> +
+
+ ))} +
+
); }; +const Console = () => { + return
} />; +}; + export default Console;