mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 21:27:20 +00:00
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 { 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 />;
|
||||
};
|
||||
|
||||
|
||||
Reference in New Issue
Block a user