fix: first workspace create logic (#1773)

This commit is contained in:
Peng Xiao
2023-04-01 01:40:30 +08:00
committed by GitHub
parent fd65dd66a1
commit 7299efe16a
20 changed files with 158 additions and 87 deletions

View File

@@ -1,3 +1,4 @@
import { DebugLogger } from '@affine/debug';
import type { NextPage } from 'next';
import { useRouter } from 'next/router';
import React, { Suspense, useEffect } from 'react';
@@ -9,6 +10,8 @@ import { RouteLogic, useRouterHelper } from '../hooks/use-router-helper';
import { useWorkspaces } from '../hooks/use-workspaces';
import { WorkspaceSubPath } from '../shared';
const logger = new DebugLogger('IndexPage');
const IndexPageInner = () => {
const router = useRouter();
const { jumpToPage, jumpToSubPath } = useRouterHelper(router);
@@ -28,11 +31,13 @@ const IndexPageInner = () => {
const pageId =
targetWorkspace.blockSuiteWorkspace.meta.pageMetas.at(0)?.id;
if (pageId) {
logger.debug('Found target workspace. Jump to page', pageId);
jumpToPage(targetWorkspace.id, pageId, RouteLogic.REPLACE);
return;
} else {
const clearId = setTimeout(() => {
dispose.dispose();
logger.debug('Found target workspace. Jump to all pages');
jumpToSubPath(
targetWorkspace.id,
WorkspaceSubPath.ALL,
@@ -50,6 +55,7 @@ const IndexPageInner = () => {
};
}
} else {
logger.debug('No target workspace. jump to all pages');
// fixme: should create new workspace
jumpToSubPath('ERROR', WorkspaceSubPath.ALL, RouteLogic.REPLACE);
}

View File

@@ -1,4 +1,5 @@
import { useTranslation } from '@affine/i18n';
import { atomWithSyncStorage } from '@affine/jotai';
import { currentAffineUserAtom } from '@affine/workspace/affine/atom';
import {
getLoginStorage,
@@ -15,7 +16,6 @@ import {
import { SettingsIcon } from '@blocksuite/icons';
import { assertExists } from '@blocksuite/store';
import { useAtom, useSetAtom } from 'jotai';
import { atomWithStorage } from 'jotai/utils';
import Head from 'next/head';
import { useRouter } from 'next/router';
import React, { useCallback, useEffect } from 'react';
@@ -32,7 +32,7 @@ import { WorkspaceLayout } from '../../../layouts';
import { WorkspacePlugins } from '../../../plugins';
import type { NextPageWithLayout } from '../../../shared';
const settingPanelAtom = atomWithStorage<SettingPanel>(
const settingPanelAtom = atomWithSyncStorage<SettingPanel>(
'workspaceId',
settingPanel.General
);