mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-26 02:35:58 +08:00
refactor: use useRouterHelper (#1422)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
@@ -6,6 +6,7 @@ import { NextRouter } from 'next/router';
|
|||||||
import React from 'react';
|
import React from 'react';
|
||||||
|
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
|
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
|
||||||
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import { BlockSuiteWorkspace } from '../../../shared';
|
import { BlockSuiteWorkspace } from '../../../shared';
|
||||||
import { StyledModalFooterContent } from './style';
|
import { StyledModalFooterContent } from './style';
|
||||||
|
|
||||||
@@ -24,6 +25,7 @@ export const Footer: React.FC<FooterProps> = ({
|
|||||||
}) => {
|
}) => {
|
||||||
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
const { createPage } = useBlockSuiteWorkspaceHelper(blockSuiteWorkspace);
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<Command.Item
|
<Command.Item
|
||||||
@@ -33,13 +35,7 @@ export const Footer: React.FC<FooterProps> = ({
|
|||||||
const id = nanoid();
|
const id = nanoid();
|
||||||
const pageId = await createPage(id, query);
|
const pageId = await createPage(id, query);
|
||||||
assertEquals(pageId, id);
|
assertEquals(pageId, id);
|
||||||
router.push({
|
jumpToPage(blockSuiteWorkspace.id, pageId);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: blockSuiteWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StyledModalFooterContent>
|
<StyledModalFooterContent>
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import React, { Dispatch, SetStateAction, useEffect, useState } from 'react';
|
|||||||
import { useRecentlyViewed } from '../../../hooks/affine/use-recent-views';
|
import { useRecentlyViewed } from '../../../hooks/affine/use-recent-views';
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
|
import { useBlockSuiteWorkspaceHelper } from '../../../hooks/use-blocksuite-workspace-helper';
|
||||||
import { usePageMeta } from '../../../hooks/use-page-meta';
|
import { usePageMeta } from '../../../hooks/use-page-meta';
|
||||||
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import { BlockSuiteWorkspace } from '../../../shared';
|
import { BlockSuiteWorkspace } from '../../../shared';
|
||||||
import { useSwitchToConfig } from './config';
|
import { useSwitchToConfig } from './config';
|
||||||
import { NoResultSVG } from './NoResultSVG';
|
import { NoResultSVG } from './NoResultSVG';
|
||||||
@@ -36,6 +37,7 @@ export const Results: React.FC<ResultsProps> = ({
|
|||||||
const [results, setResults] = useState(new Map<string, string | undefined>());
|
const [results, setResults] = useState(new Map<string, string | undefined>());
|
||||||
const recentlyViewed = useRecentlyViewed();
|
const recentlyViewed = useRecentlyViewed();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
setResults(blockSuiteWorkspace.search(query));
|
setResults(blockSuiteWorkspace.search(query));
|
||||||
//Save the Map<BlockId, PageId> obtained from the search as state
|
//Save the Map<BlockId, PageId> obtained from the search as state
|
||||||
@@ -65,14 +67,7 @@ export const Results: React.FC<ResultsProps> = ({
|
|||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
onClose();
|
onClose();
|
||||||
assertExists(blockSuiteWorkspace.id);
|
assertExists(blockSuiteWorkspace.id);
|
||||||
// fixme: refactor to `useRouterHelper`
|
jumpToPage(blockSuiteWorkspace.id, result.id);
|
||||||
router.push({
|
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: blockSuiteWorkspace.id,
|
|
||||||
pageId: result.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
value={result.id}
|
value={result.id}
|
||||||
>
|
>
|
||||||
@@ -105,13 +100,7 @@ export const Results: React.FC<ResultsProps> = ({
|
|||||||
value={recent.id}
|
value={recent.id}
|
||||||
onSelect={() => {
|
onSelect={() => {
|
||||||
onClose();
|
onClose();
|
||||||
router.push({
|
jumpToPage(blockSuiteWorkspace.id, recent.id);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: blockSuiteWorkspace.id,
|
|
||||||
pageId: recent.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<StyledListItem>
|
<StyledListItem>
|
||||||
|
|||||||
@@ -24,6 +24,19 @@ export function useRouterHelper(router: NextRouter) {
|
|||||||
},
|
},
|
||||||
});
|
});
|
||||||
},
|
},
|
||||||
|
jumpToPublicWorkspacePage: (
|
||||||
|
workspaceId: string,
|
||||||
|
pageId: string,
|
||||||
|
logic: RouteLogic = RouteLogic.PUSH
|
||||||
|
) => {
|
||||||
|
return router[logic]({
|
||||||
|
pathname: `/public-workspace/[workspaceId]/[pageId]`,
|
||||||
|
query: {
|
||||||
|
workspaceId,
|
||||||
|
pageId,
|
||||||
|
},
|
||||||
|
});
|
||||||
|
},
|
||||||
jumpToSubPath: (
|
jumpToSubPath: (
|
||||||
workspaceId: string,
|
workspaceId: string,
|
||||||
subPath: WorkspaceSubPath,
|
subPath: WorkspaceSubPath,
|
||||||
|
|||||||
@@ -23,6 +23,7 @@ import { useCurrentPageId } from '../hooks/current/use-current-page-id';
|
|||||||
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../hooks/current/use-current-workspace';
|
||||||
import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper';
|
import { useBlockSuiteWorkspaceHelper } from '../hooks/use-blocksuite-workspace-helper';
|
||||||
import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace';
|
import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace';
|
||||||
|
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||||
import { useRouterTitle } from '../hooks/use-router-title';
|
import { useRouterTitle } from '../hooks/use-router-title';
|
||||||
import { useWorkspaces } from '../hooks/use-workspaces';
|
import { useWorkspaces } from '../hooks/use-workspaces';
|
||||||
import { WorkspacePlugins } from '../plugins';
|
import { WorkspacePlugins } from '../plugins';
|
||||||
@@ -131,6 +132,7 @@ export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
|||||||
}
|
}
|
||||||
}, [currentWorkspace]);
|
}, [currentWorkspace]);
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToPage, jumpToPublicWorkspacePage } = useRouterHelper(router);
|
||||||
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);
|
const [, setOpenWorkspacesModal] = useAtom(openWorkspacesModalAtom);
|
||||||
const helper = useBlockSuiteWorkspaceHelper(
|
const helper = useBlockSuiteWorkspaceHelper(
|
||||||
currentWorkspace?.blockSuiteWorkspace ?? null
|
currentWorkspace?.blockSuiteWorkspace ?? null
|
||||||
@@ -141,17 +143,13 @@ export const WorkspaceLayoutInner: React.FC<React.PropsWithChildren> = ({
|
|||||||
const handleOpenPage = useCallback(
|
const handleOpenPage = useCallback(
|
||||||
(pageId: string) => {
|
(pageId: string) => {
|
||||||
assertExists(currentWorkspace);
|
assertExists(currentWorkspace);
|
||||||
router.push({
|
if (isPublicWorkspace) {
|
||||||
pathname: `/${
|
jumpToPublicWorkspacePage(currentWorkspace.id, pageId);
|
||||||
isPublicWorkspace ? 'public-workspace' : 'workspace'
|
} else {
|
||||||
}/[workspaceId]/[pageId]`,
|
jumpToPage(currentWorkspace.id, pageId);
|
||||||
query: {
|
}
|
||||||
workspaceId: currentWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[currentWorkspace, isPublicWorkspace, router]
|
[currentWorkspace, isPublicWorkspace, jumpToPage, jumpToPublicWorkspacePage]
|
||||||
);
|
);
|
||||||
const handleCreatePage = useCallback(async () => {
|
const handleCreatePage = useCallback(async () => {
|
||||||
return helper.createPage(nanoid());
|
return helper.createPage(nanoid());
|
||||||
|
|||||||
@@ -5,10 +5,13 @@ import React, { Suspense, useEffect } from 'react';
|
|||||||
import { PageLoading } from '../components/pure/loading';
|
import { PageLoading } from '../components/pure/loading';
|
||||||
import { useLastWorkspaceId } from '../hooks/affine/use-last-leave-workspace-id';
|
import { useLastWorkspaceId } from '../hooks/affine/use-last-leave-workspace-id';
|
||||||
import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace';
|
import { useCreateFirstWorkspace } from '../hooks/use-create-first-workspace';
|
||||||
|
import { RouteLogic, useRouterHelper } from '../hooks/use-router-helper';
|
||||||
import { useWorkspaces } from '../hooks/use-workspaces';
|
import { useWorkspaces } from '../hooks/use-workspaces';
|
||||||
|
import { WorkspaceSubPath } from '../shared';
|
||||||
|
|
||||||
const IndexPageInner = () => {
|
const IndexPageInner = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToPage, jumpToSubPath } = useRouterHelper(router);
|
||||||
const workspaces = useWorkspaces();
|
const workspaces = useWorkspaces();
|
||||||
const lastWorkspaceId = useLastWorkspaceId();
|
const lastWorkspaceId = useLastWorkspaceId();
|
||||||
|
|
||||||
@@ -25,34 +28,21 @@ const IndexPageInner = () => {
|
|||||||
const pageId =
|
const pageId =
|
||||||
targetWorkspace.blockSuiteWorkspace.meta.pageMetas.at(0)?.id;
|
targetWorkspace.blockSuiteWorkspace.meta.pageMetas.at(0)?.id;
|
||||||
if (pageId) {
|
if (pageId) {
|
||||||
router.replace({
|
jumpToPage(targetWorkspace.id, pageId, RouteLogic.REPLACE);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: targetWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
return;
|
return;
|
||||||
} else {
|
} else {
|
||||||
const clearId = setTimeout(() => {
|
const clearId = setTimeout(() => {
|
||||||
dispose.dispose();
|
dispose.dispose();
|
||||||
router.replace({
|
jumpToSubPath(
|
||||||
pathname: '/workspace/[workspaceId]/all',
|
targetWorkspace.id,
|
||||||
query: {
|
WorkspaceSubPath.ALL,
|
||||||
workspaceId: targetWorkspace.id,
|
RouteLogic.REPLACE
|
||||||
},
|
);
|
||||||
});
|
|
||||||
}, 1000);
|
}, 1000);
|
||||||
const dispose =
|
const dispose =
|
||||||
targetWorkspace.blockSuiteWorkspace.slots.pageAdded.once(pageId => {
|
targetWorkspace.blockSuiteWorkspace.slots.pageAdded.once(pageId => {
|
||||||
clearTimeout(clearId);
|
clearTimeout(clearId);
|
||||||
router.replace({
|
jumpToPage(targetWorkspace.id, pageId, RouteLogic.REPLACE);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: targetWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
return () => {
|
return () => {
|
||||||
clearTimeout(clearId);
|
clearTimeout(clearId);
|
||||||
@@ -60,7 +50,7 @@ const IndexPageInner = () => {
|
|||||||
};
|
};
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [lastWorkspaceId, router, workspaces]);
|
}, [jumpToPage, jumpToSubPath, lastWorkspaceId, router, workspaces]);
|
||||||
|
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -14,11 +14,13 @@ import useSWR from 'swr';
|
|||||||
import inviteError from '../../../public/imgs/invite-error.svg';
|
import inviteError from '../../../public/imgs/invite-error.svg';
|
||||||
import inviteSuccess from '../../../public/imgs/invite-success.svg';
|
import inviteSuccess from '../../../public/imgs/invite-success.svg';
|
||||||
import { PageLoading } from '../../components/pure/loading';
|
import { PageLoading } from '../../components/pure/loading';
|
||||||
|
import { RouteLogic, useRouterHelper } from '../../hooks/use-router-helper';
|
||||||
import { QueryKey } from '../../plugins/affine/fetcher';
|
import { QueryKey } from '../../plugins/affine/fetcher';
|
||||||
import { NextPageWithLayout } from '../../shared';
|
import { NextPageWithLayout, WorkspaceSubPath } from '../../shared';
|
||||||
|
|
||||||
const InvitePage: NextPageWithLayout = () => {
|
const InvitePage: NextPageWithLayout = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToSubPath } = useRouterHelper(router);
|
||||||
const { data: inviteData } = useSWR<Permission>(
|
const { data: inviteData } = useSWR<Permission>(
|
||||||
typeof router.query.invite_code === 'string'
|
typeof router.query.invite_code === 'string'
|
||||||
? [QueryKey.acceptInvite, router.query.invite_code]
|
? [QueryKey.acceptInvite, router.query.invite_code]
|
||||||
@@ -33,12 +35,11 @@ const InvitePage: NextPageWithLayout = () => {
|
|||||||
type="primary"
|
type="primary"
|
||||||
shape="round"
|
shape="round"
|
||||||
onClick={() => {
|
onClick={() => {
|
||||||
router.replace({
|
jumpToSubPath(
|
||||||
pathname: `/workspace/[workspaceId]/all`,
|
inviteData.workspace_id,
|
||||||
query: {
|
WorkspaceSubPath.ALL,
|
||||||
workspaceId: inviteData.workspace_id,
|
RouteLogic.REPLACE
|
||||||
},
|
);
|
||||||
});
|
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
Go to Workspace
|
Go to Workspace
|
||||||
|
|||||||
@@ -12,12 +12,14 @@ import {
|
|||||||
import { PageLoading } from '../../../components/pure/loading';
|
import { PageLoading } from '../../../components/pure/loading';
|
||||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||||
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
||||||
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 [currentWorkspace] = useCurrentWorkspace();
|
const [currentWorkspace] = useCurrentWorkspace();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
useSyncRouterWithCurrentWorkspace(router);
|
useSyncRouterWithCurrentWorkspace(router);
|
||||||
@@ -33,33 +35,21 @@ const AllPage: NextPageWithLayout = () => {
|
|||||||
init: true,
|
init: true,
|
||||||
});
|
});
|
||||||
assertExists(pageId, id);
|
assertExists(pageId, id);
|
||||||
router.push({
|
jumpToPage(currentWorkspace.id, pageId);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: currentWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
});
|
});
|
||||||
currentWorkspace.blockSuiteWorkspace.createPage(pageId);
|
currentWorkspace.blockSuiteWorkspace.createPage(pageId);
|
||||||
}
|
}
|
||||||
}, [currentWorkspace, router]);
|
}, [currentWorkspace, jumpToPage, router]);
|
||||||
const onClickPage = useCallback(
|
const onClickPage = useCallback(
|
||||||
(pageId: string, newTab?: boolean) => {
|
(pageId: string, newTab?: boolean) => {
|
||||||
assertExists(currentWorkspace);
|
assertExists(currentWorkspace);
|
||||||
if (newTab) {
|
if (newTab) {
|
||||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||||
} else {
|
} else {
|
||||||
router.push({
|
jumpToPage(currentWorkspace.id, pageId);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: currentWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentWorkspace, router]
|
[currentWorkspace, jumpToPage]
|
||||||
);
|
);
|
||||||
if (!router.isReady) {
|
if (!router.isReady) {
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import PageList from '../../../components/blocksuite/block-suite-page-list/page-
|
|||||||
import { PageLoading } from '../../../components/pure/loading';
|
import { PageLoading } from '../../../components/pure/loading';
|
||||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||||
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
||||||
import { WorkspaceLayout } from '../../../layouts';
|
import { WorkspaceLayout } from '../../../layouts';
|
||||||
import { NextPageWithLayout } from '../../../shared';
|
import { NextPageWithLayout } from '../../../shared';
|
||||||
|
|
||||||
const FavouritePage: NextPageWithLayout = () => {
|
const FavouritePage: NextPageWithLayout = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
const [currentWorkspace] = useCurrentWorkspace();
|
const [currentWorkspace] = useCurrentWorkspace();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
useSyncRouterWithCurrentWorkspace(router);
|
useSyncRouterWithCurrentWorkspace(router);
|
||||||
@@ -24,16 +26,10 @@ const FavouritePage: NextPageWithLayout = () => {
|
|||||||
if (newTab) {
|
if (newTab) {
|
||||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||||
} else {
|
} else {
|
||||||
router.push({
|
jumpToPage(currentWorkspace.id, pageId);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: currentWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentWorkspace, router]
|
[currentWorkspace, jumpToPage]
|
||||||
);
|
);
|
||||||
if (currentWorkspace === null) {
|
if (currentWorkspace === null) {
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
|
|||||||
@@ -9,12 +9,14 @@ import PageList from '../../../components/blocksuite/block-suite-page-list/page-
|
|||||||
import { PageLoading } from '../../../components/pure/loading';
|
import { PageLoading } from '../../../components/pure/loading';
|
||||||
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
import { WorkspaceTitle } from '../../../components/pure/workspace-title';
|
||||||
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
import { useCurrentWorkspace } from '../../../hooks/current/use-current-workspace';
|
||||||
|
import { useRouterHelper } from '../../../hooks/use-router-helper';
|
||||||
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
import { useSyncRouterWithCurrentWorkspace } from '../../../hooks/use-sync-router-with-current-workspace';
|
||||||
import { WorkspaceLayout } from '../../../layouts';
|
import { WorkspaceLayout } from '../../../layouts';
|
||||||
import { NextPageWithLayout } from '../../../shared';
|
import { NextPageWithLayout } from '../../../shared';
|
||||||
|
|
||||||
const TrashPage: NextPageWithLayout = () => {
|
const TrashPage: NextPageWithLayout = () => {
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
const [currentWorkspace] = useCurrentWorkspace();
|
const [currentWorkspace] = useCurrentWorkspace();
|
||||||
const { t } = useTranslation();
|
const { t } = useTranslation();
|
||||||
useSyncRouterWithCurrentWorkspace(router);
|
useSyncRouterWithCurrentWorkspace(router);
|
||||||
@@ -24,16 +26,10 @@ const TrashPage: NextPageWithLayout = () => {
|
|||||||
if (newTab) {
|
if (newTab) {
|
||||||
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
window.open(`/workspace/${currentWorkspace?.id}/${pageId}`, '_blank');
|
||||||
} else {
|
} else {
|
||||||
router.push({
|
jumpToPage(currentWorkspace.id, pageId);
|
||||||
pathname: '/workspace/[workspaceId]/[pageId]',
|
|
||||||
query: {
|
|
||||||
workspaceId: currentWorkspace.id,
|
|
||||||
pageId,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
[currentWorkspace, router]
|
[currentWorkspace, jumpToPage]
|
||||||
);
|
);
|
||||||
if (!router.isReady) {
|
if (!router.isReady) {
|
||||||
return <PageLoading />;
|
return <PageLoading />;
|
||||||
|
|||||||
@@ -9,7 +9,9 @@ import {
|
|||||||
openWorkspacesModalAtom,
|
openWorkspacesModalAtom,
|
||||||
} from '../atoms';
|
} from '../atoms';
|
||||||
import { useCurrentUser } from '../hooks/current/use-current-user';
|
import { useCurrentUser } from '../hooks/current/use-current-user';
|
||||||
|
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||||
import { useWorkspaces, useWorkspacesHelper } from '../hooks/use-workspaces';
|
import { useWorkspaces, useWorkspacesHelper } from '../hooks/use-workspaces';
|
||||||
|
import { WorkspaceSubPath } from '../shared';
|
||||||
import { apis } from '../shared/apis';
|
import { apis } from '../shared/apis';
|
||||||
|
|
||||||
const WorkspaceListModal = dynamic(
|
const WorkspaceListModal = dynamic(
|
||||||
@@ -31,6 +33,7 @@ export function Modals() {
|
|||||||
);
|
);
|
||||||
|
|
||||||
const router = useRouter();
|
const router = useRouter();
|
||||||
|
const { jumpToSubPath } = useRouterHelper(router);
|
||||||
const user = useCurrentUser();
|
const user = useCurrentUser();
|
||||||
const workspaces = useWorkspaces();
|
const workspaces = useWorkspaces();
|
||||||
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
||||||
@@ -51,14 +54,9 @@ export function Modals() {
|
|||||||
workspace => {
|
workspace => {
|
||||||
setOpenWorkspacesModal(false);
|
setOpenWorkspacesModal(false);
|
||||||
setCurrentWorkspace(workspace.id);
|
setCurrentWorkspace(workspace.id);
|
||||||
router.push({
|
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||||
pathname: `/workspace/[workspaceId]/all`,
|
|
||||||
query: {
|
|
||||||
workspaceId: workspace.id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[router, setCurrentWorkspace, setOpenWorkspacesModal]
|
[jumpToSubPath, setCurrentWorkspace, setOpenWorkspacesModal]
|
||||||
)}
|
)}
|
||||||
onClickLogin={useCallback(() => {
|
onClickLogin={useCallback(() => {
|
||||||
apis.signInWithGoogle().then(() => {
|
apis.signInWithGoogle().then(() => {
|
||||||
@@ -83,16 +81,11 @@ export function Modals() {
|
|||||||
const id = await createLocalWorkspace(name);
|
const id = await createLocalWorkspace(name);
|
||||||
setOpenCreateWorkspaceModal(false);
|
setOpenCreateWorkspaceModal(false);
|
||||||
setOpenWorkspacesModal(false);
|
setOpenWorkspacesModal(false);
|
||||||
return router.push({
|
return jumpToSubPath(id, WorkspaceSubPath.ALL);
|
||||||
pathname: '/workspace/[workspaceId]/all',
|
|
||||||
query: {
|
|
||||||
workspaceId: id,
|
|
||||||
},
|
|
||||||
});
|
|
||||||
},
|
},
|
||||||
[
|
[
|
||||||
createLocalWorkspace,
|
createLocalWorkspace,
|
||||||
router,
|
jumpToSubPath,
|
||||||
setOpenCreateWorkspaceModal,
|
setOpenCreateWorkspaceModal,
|
||||||
setOpenWorkspacesModal,
|
setOpenWorkspacesModal,
|
||||||
]
|
]
|
||||||
|
|||||||
Reference in New Issue
Block a user