feat: update the strategy of workspace id and page id generator

This commit is contained in:
tzhangchi
2022-12-23 21:34:07 +08:00
parent 3ac3a97794
commit 6047243d2e
2 changed files with 10 additions and 4 deletions
@@ -1,14 +1,17 @@
import { useState, useEffect } from 'react';
import { useAppState } from '@/providers/app-state-provider';
import { useRouter } from 'next/router';
// It is a fully effective hook
// Cause it not just ensure workspace loaded, but also have router change.
export const useEnsureWorkspace = () => {
const [workspaceLoaded, setWorkspaceLoaded] = useState(false);
const { workspacesMeta, loadWorkspace, synced, user } = useAppState();
const router = useRouter();
const defaultOutLineWorkspaceId = '99ce7eb7';
const defaultOutLineWorkspaceId =
'local-first-' + '85b4ca0b-9081-421d-903b-bc2501ea280f';
// const defaultOutLineWorkspaceId = '99ce7eb7';
// console.log(defaultOutLineWorkspaceId);
useEffect(() => {
if (!synced) {
setWorkspaceLoaded(false);
@@ -23,6 +26,7 @@ export const useEnsureWorkspace = () => {
meta => meta.id.toString() === router.query.workspaceId
) === -1
) {
debugger;
router.push('/404');
return;
}
@@ -32,6 +36,8 @@ export const useEnsureWorkspace = () => {
router.query.workspaceId &&
router.query.workspaceId !== defaultOutLineWorkspaceId
) {
debugger;
router.push('/404');
return;
}