mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-07-19 02:56:23 +08:00
refactor: use useRouterHelper (#1422)
Co-authored-by: himself65 <himself65@outlook.com>
This commit is contained in:
@@ -9,7 +9,9 @@ import {
|
||||
openWorkspacesModalAtom,
|
||||
} from '../atoms';
|
||||
import { useCurrentUser } from '../hooks/current/use-current-user';
|
||||
import { useRouterHelper } from '../hooks/use-router-helper';
|
||||
import { useWorkspaces, useWorkspacesHelper } from '../hooks/use-workspaces';
|
||||
import { WorkspaceSubPath } from '../shared';
|
||||
import { apis } from '../shared/apis';
|
||||
|
||||
const WorkspaceListModal = dynamic(
|
||||
@@ -31,6 +33,7 @@ export function Modals() {
|
||||
);
|
||||
|
||||
const router = useRouter();
|
||||
const { jumpToSubPath } = useRouterHelper(router);
|
||||
const user = useCurrentUser();
|
||||
const workspaces = useWorkspaces();
|
||||
const currentWorkspaceId = useAtomValue(currentWorkspaceIdAtom);
|
||||
@@ -51,14 +54,9 @@ export function Modals() {
|
||||
workspace => {
|
||||
setOpenWorkspacesModal(false);
|
||||
setCurrentWorkspace(workspace.id);
|
||||
router.push({
|
||||
pathname: `/workspace/[workspaceId]/all`,
|
||||
query: {
|
||||
workspaceId: workspace.id,
|
||||
},
|
||||
});
|
||||
jumpToSubPath(workspace.id, WorkspaceSubPath.ALL);
|
||||
},
|
||||
[router, setCurrentWorkspace, setOpenWorkspacesModal]
|
||||
[jumpToSubPath, setCurrentWorkspace, setOpenWorkspacesModal]
|
||||
)}
|
||||
onClickLogin={useCallback(() => {
|
||||
apis.signInWithGoogle().then(() => {
|
||||
@@ -83,16 +81,11 @@ export function Modals() {
|
||||
const id = await createLocalWorkspace(name);
|
||||
setOpenCreateWorkspaceModal(false);
|
||||
setOpenWorkspacesModal(false);
|
||||
return router.push({
|
||||
pathname: '/workspace/[workspaceId]/all',
|
||||
query: {
|
||||
workspaceId: id,
|
||||
},
|
||||
});
|
||||
return jumpToSubPath(id, WorkspaceSubPath.ALL);
|
||||
},
|
||||
[
|
||||
createLocalWorkspace,
|
||||
router,
|
||||
jumpToSubPath,
|
||||
setOpenCreateWorkspaceModal,
|
||||
setOpenWorkspacesModal,
|
||||
]
|
||||
|
||||
Reference in New Issue
Block a user