fix: load page on first render (#1155)

This commit is contained in:
Himself65 authored and GitHub committed 2023-02-21 05:18:30 +00:00
1 parent edd8f347bc
commit 1731db833d
1 file changed
+14 -2
+14 -2
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) {
api
.getState()
.loadWorkspace(targetWorkspace.id)
.then(() => {
router.push(`/workspace/${targetWorkspace.id}`);
});
}
}, [targetWorkspace, exist, router]);
}, [targetWorkspace, exist, router, api]);
return <PageLoading />;
};