From 703ea8716c2e8441460e397e1173e791c2edf887 Mon Sep 17 00:00:00 2001 From: Tristan Yang Date: Wed, 14 Dec 2022 16:47:01 +0800 Subject: [PATCH] refactor: replace isLoading with isSuccess --- .vscode/settings.json | 1 + src/app/services/handlers.ts | 2 +- src/app/services/user.ts | 2 -- src/common/component/RequireAuth.tsx | 7 ++++--- src/routes/home/index.tsx | 4 ++-- 5 files changed, 8 insertions(+), 8 deletions(-) diff --git a/.vscode/settings.json b/.vscode/settings.json index 94b7fd94..54ffec97 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -34,6 +34,7 @@ "boardos", "btns", "favs", + "localforage", "localstorage", "magiclink", "navs", diff --git a/src/app/services/handlers.ts b/src/app/services/handlers.ts index bc6de18b..a8a0f7d8 100644 --- a/src/app/services/handlers.ts +++ b/src/app/services/handlers.ts @@ -23,7 +23,7 @@ export const onMessageSendStarted = async ( if (type == "archive") return; // id: who send to ,from_uid: who sent // console.log("handlers data", content, type, properties, ignoreLocal, id); - const isMedia = ["image", "video", "audio"].includes(properties.content_type.split('/')[0]); + const isMedia = properties.content_type ? ["image", "video", "audio"].includes(properties.content_type.split('/')[0]) : false; // const isImage = properties.content_type?.startsWith("image"); const ts = properties.local_id || +new Date(); const tmpMsg = { diff --git a/src/app/services/user.ts b/src/app/services/user.ts index 5409905a..9922f8b2 100644 --- a/src/app/services/user.ts +++ b/src/app/services/user.ts @@ -28,11 +28,9 @@ export const userApi = createApi({ }); }, async onQueryStarted(data, { dispatch, queryFulfilled }) { - // const local_uid = Number(localStorage.getItem(KEY_UID)); try { const { data: users } = await queryFulfilled; dispatch(fillUsers(users)); - // } } catch { console.log("get user list error"); } diff --git a/src/common/component/RequireAuth.tsx b/src/common/component/RequireAuth.tsx index 7ec11944..fb675c55 100644 --- a/src/common/component/RequireAuth.tsx +++ b/src/common/component/RequireAuth.tsx @@ -16,12 +16,13 @@ const RequireAuth: FC = ({ children, redirectTo = "/login" }) => { const location = useLocation(); const matchs = matchRoutes(GuestAllows, location); const allowGuest = matchs ? !!matchs[0].pathname : false; - const { data: loginConfig, isLoading: fetchingLoginConfig } = useGetLoginConfigQuery(); - const { isLoading: checkingInitial } = useGetInitializedQuery(); + const { data: loginConfig, isSuccess: loginConfigSuccess } = useGetLoginConfigQuery(); + const { isSuccess: checkInitialSuccess } = useGetInitializedQuery(); const { token, guest, initialized } = useAppSelector((store) => store.authData); + // console.log("auth route", { checkInitialSuccess, loginConfigSuccess, initialized, guest: loginConfig?.guest, token, allowGuest, guest }); // 初始化和login配置检查 - if (checkingInitial || fetchingLoginConfig) return null; + if (!checkInitialSuccess || !loginConfigSuccess) return null; // 未初始化 则先走setup 流程 if (!initialized) return ; // 开启guest 并且没token 而且是允许guest访问的路由 则先去过渡页登录 diff --git a/src/routes/home/index.tsx b/src/routes/home/index.tsx index b9f14a48..e2f6df1d 100644 --- a/src/routes/home/index.tsx +++ b/src/routes/home/index.tsx @@ -36,8 +36,8 @@ function HomePage() { guest: store.authData.guest }; }); - const { loading } = usePreload(); - if (loading || !ready) { + const { success } = usePreload(); + if (!success || !ready) { return ; } const isSettingPage = pathname.startsWith("/setting");