fix: load page on first render (#1155)
This commit is contained in:
@@ -1,19 +1,31 @@
|
|||||||
|
import { useGlobalStateApi } from '@affine/store';
|
||||||
import { useRouter } from 'next/router';
|
import { useRouter } from 'next/router';
|
||||||
import { useEffect } from 'react';
|
import { useEffect, useRef } from 'react';
|
||||||
|
|
||||||
import { PageLoading } from '@/components/loading';
|
import { PageLoading } from '@/components/loading';
|
||||||
import { useRouterTargetWorkspace } from '@/hooks/use-router-target-workspace';
|
import { useRouterTargetWorkspace } from '@/hooks/use-router-target-workspace';
|
||||||
|
|
||||||
export const WorkspaceIndex = () => {
|
export const WorkspaceIndex = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const api = useGlobalStateApi();
|
||||||
const { targetWorkspace, exist } = useRouterTargetWorkspace();
|
const { targetWorkspace, exist } = useRouterTargetWorkspace();
|
||||||
|
const onceRef = useRef(true);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
|
if (!onceRef.current) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
onceRef.current = true;
|
||||||
if (!exist) {
|
if (!exist) {
|
||||||
router.push('/404');
|
router.push('/404');
|
||||||
} else if (targetWorkspace) {
|
} else if (targetWorkspace) {
|
||||||
|
api
|
||||||
|
.getState()
|
||||||
|
.loadWorkspace(targetWorkspace.id)
|
||||||
|
.then(() => {
|
||||||
router.push(`/workspace/${targetWorkspace.id}`);
|
router.push(`/workspace/${targetWorkspace.id}`);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
}, [targetWorkspace, exist, router]);
|
}, [targetWorkspace, exist, router, api]);
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user