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;
}
@@ -5,7 +5,6 @@ import {
token,
AccessTokenMessage,
getWorkspaces,
downloadWorkspace,
} from '@pathfinder/data-services';
import { AppState, AppStateContext } from './context';
import type {
@@ -15,6 +14,7 @@ import type {
} from './context';
import { Page, Workspace as StoreWorkspace } from '@blocksuite/store';
import { EditorContainer } from '@blocksuite/editor';
import { uuidv4 as uuidv4IdGenerator } from '@blocksuite/store';
const DynamicBlocksuite = dynamic(() => import('./dynamic-blocksuite'), {
ssr: false,
});
@@ -153,7 +153,7 @@ export const AppStateProvider = ({ children }: { children?: ReactNode }) => {
Promise.resolve(null)
);
createPage.current = (pageId: string = Date.now().toString()) =>
createPage.current = (pageId: string = 'lp-' + uuidv4IdGenerator()) =>
new Promise<string | null>(resolve => {
const { currentWorkspace } = state;
if (!currentWorkspace) {