fix: load page on first render (#1155)

This commit is contained in:
Himself65
2023-02-20 23:18:30 -06:00
committed by GitHub
parent edd8f347bc
commit 1731db833d

View File

@@ -1,19 +1,31 @@
import { useGlobalStateApi } from '@affine/store';
import { useRouter } from 'next/router';
import { useEffect } from 'react';
import { useEffect, useRef } from 'react';
import { PageLoading } from '@/components/loading';
import { useRouterTargetWorkspace } from '@/hooks/use-router-target-workspace';
export const WorkspaceIndex = () => {
const router = useRouter();
const api = useGlobalStateApi();
const { targetWorkspace, exist } = useRouterTargetWorkspace();
const onceRef = useRef(true);
useEffect(() => {
if (!onceRef.current) {
return;
}
onceRef.current = true;
if (!exist) {
router.push('/404');
} else if (targetWorkspace) {
router.push(`/workspace/${targetWorkspace.id}`);
api
.getState()
.loadWorkspace(targetWorkspace.id)
.then(() => {
router.push(`/workspace/${targetWorkspace.id}`);
});
}
}, [targetWorkspace, exist, router]);
}, [targetWorkspace, exist, router, api]);
return <PageLoading />;
};