fix: create a new page when refresh (#1440)

This commit is contained in:
Himself65
2023-03-09 02:10:02 -06:00
committed by GitHub
parent 6594d2d47b
commit 373953b8ae
2 changed files with 19 additions and 12 deletions
@@ -17,6 +17,7 @@ import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-route
import { WorkspaceLayout } from '../../../layouts'; import { WorkspaceLayout } from '../../../layouts';
import { WorkspacePlugins } from '../../../plugins'; import { WorkspacePlugins } from '../../../plugins';
import { NextPageWithLayout, RemWorkspaceFlavour } from '../../../shared'; import { NextPageWithLayout, RemWorkspaceFlavour } from '../../../shared';
const AllPage: NextPageWithLayout = () => { const AllPage: NextPageWithLayout = () => {
const router = useRouter(); const router = useRouter();
const { jumpToPage } = useRouterHelper(router); const { jumpToPage } = useRouterHelper(router);
@@ -27,6 +28,7 @@ const AllPage: NextPageWithLayout = () => {
if (!router.isReady) { if (!router.isReady) {
return; return;
} }
const id = setTimeout(() => {
if (currentWorkspace?.blockSuiteWorkspace.isEmpty) { if (currentWorkspace?.blockSuiteWorkspace.isEmpty) {
// this is a new workspace, so we should redirect to the new page // this is a new workspace, so we should redirect to the new page
const pageId = nanoid(); const pageId = nanoid();
@@ -39,6 +41,10 @@ const AllPage: NextPageWithLayout = () => {
}); });
currentWorkspace.blockSuiteWorkspace.createPage(pageId); currentWorkspace.blockSuiteWorkspace.createPage(pageId);
} }
}, 1000);
return () => {
clearTimeout(id);
};
}, [currentWorkspace, jumpToPage, router]); }, [currentWorkspace, jumpToPage, router]);
const onClickPage = useCallback( const onClickPage = useCallback(
(pageId: string, newTab?: boolean) => { (pageId: string, newTab?: boolean) => {
+2 -1
View File
@@ -10,10 +10,11 @@ test.describe('Shortcuts Modal', () => {
await page.locator('[data-testid=help-island]').click(); await page.locator('[data-testid=help-island]').click();
const shortcutsIcon = page.locator('[data-testid=shortcuts-icon]'); const shortcutsIcon = page.locator('[data-testid=shortcuts-icon]');
await page.waitForTimeout(1000);
expect(await shortcutsIcon.isVisible()).toEqual(true); expect(await shortcutsIcon.isVisible()).toEqual(true);
await shortcutsIcon.click(); await shortcutsIcon.click();
await page.waitForTimeout(800); await page.waitForTimeout(1000);
const shortcutsModal = page.locator('[data-testid=shortcuts-modal]'); const shortcutsModal = page.locator('[data-testid=shortcuts-modal]');
await expect(shortcutsModal).toContainText('Keyboard Shortcuts'); await expect(shortcutsModal).toContainText('Keyboard Shortcuts');
}); });