From e1ca69aaf9dfda7093c5ca2cd45c9ffb175dce18 Mon Sep 17 00:00:00 2001 From: alt0 Date: Thu, 22 Dec 2022 22:14:42 +0800 Subject: [PATCH] fix: if jump in [workspace]/index, should manually load workspace --- .../app/src/pages/workspace/[workspaceId]/index.tsx | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/packages/app/src/pages/workspace/[workspaceId]/index.tsx b/packages/app/src/pages/workspace/[workspaceId]/index.tsx index c0f1d03f73..6c356d23fc 100644 --- a/packages/app/src/pages/workspace/[workspaceId]/index.tsx +++ b/packages/app/src/pages/workspace/[workspaceId]/index.tsx @@ -1,15 +1,20 @@ import React, { ReactElement, useEffect } from 'react'; import { useRouter } from 'next/router'; import { useAppState } from '@/providers/app-state-provider/context'; +import { useLoadWorkspace } from '@/providers/app-state-provider/hooks'; import WorkspaceLayout from '@/components/workspace-layout'; const WorkspaceIndex = () => { const router = useRouter(); - const { createPage, currentWorkspaceId, currentWorkspace } = useAppState(); + const workspace = useLoadWorkspace(); + const { createPage, currentWorkspaceId } = useAppState(); useEffect(() => { const initPage = async () => { - const savedPageId = currentWorkspace!.meta.pageMetas[0]?.id; + if (!workspace) { + return; + } + const savedPageId = workspace!.meta.pageMetas[0]?.id; if (savedPageId) { router.replace(`/workspace/${currentWorkspaceId}/${savedPageId}`); return; @@ -19,7 +24,7 @@ const WorkspaceIndex = () => { router.replace(`/workspace/${currentWorkspaceId}/${pageId}`); }; initPage(); - }, [currentWorkspace, currentWorkspaceId, createPage, router]); + }, [workspace, currentWorkspaceId, createPage, router]); return <>; };