mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-19 07:17:00 +08:00
feat(core): workbench system (#5837)
This commit is contained in:
@@ -1,21 +1,23 @@
|
||||
import type { WorkspaceSubPath } from '@affine/core/shared';
|
||||
import { useCallback, useMemo } from 'react';
|
||||
import {
|
||||
type NavigateOptions,
|
||||
useLocation,
|
||||
// eslint-disable-next-line @typescript-eslint/no-restricted-imports
|
||||
useNavigate,
|
||||
} from 'react-router-dom';
|
||||
import { type NavigateOptions, type To, useLocation } from 'react-router-dom';
|
||||
|
||||
import { router } from '../router';
|
||||
|
||||
export enum RouteLogic {
|
||||
REPLACE = 'replace',
|
||||
PUSH = 'push',
|
||||
}
|
||||
|
||||
function navigate(to: To, option?: { replace?: boolean }) {
|
||||
router.navigate(to, option).catch(err => {
|
||||
console.error('Failed to navigate', err);
|
||||
});
|
||||
}
|
||||
|
||||
// todo: add a name -> path helper in the results
|
||||
export function useNavigateHelper() {
|
||||
const location = useLocation();
|
||||
const navigate = useNavigate();
|
||||
|
||||
const jumpToPage = useCallback(
|
||||
(
|
||||
@@ -27,7 +29,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToPageBlock = useCallback(
|
||||
(
|
||||
@@ -40,7 +42,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToCollections = useCallback(
|
||||
(workspaceId: string, logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
@@ -48,7 +50,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToTags = useCallback(
|
||||
(workspaceId: string, logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
@@ -56,7 +58,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToTag = useCallback(
|
||||
(
|
||||
@@ -68,7 +70,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToCollection = useCallback(
|
||||
(
|
||||
@@ -80,7 +82,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToPublicWorkspacePage = useCallback(
|
||||
(
|
||||
@@ -92,7 +94,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
const jumpToSubPath = useCallback(
|
||||
(
|
||||
@@ -104,7 +106,7 @@ export function useNavigateHelper() {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
|
||||
const isPublicWorkspace = useMemo(() => {
|
||||
@@ -122,31 +124,22 @@ export function useNavigateHelper() {
|
||||
[jumpToPage, jumpToPublicWorkspacePage, isPublicWorkspace]
|
||||
);
|
||||
|
||||
const jumpToIndex = useCallback(
|
||||
(logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
const jumpToIndex = useCallback((logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
}, []);
|
||||
|
||||
const jumpTo404 = useCallback(
|
||||
(logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/404', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
const jumpToExpired = useCallback(
|
||||
(logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/expired', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
);
|
||||
const jumpTo404 = useCallback((logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/404', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
}, []);
|
||||
const jumpToExpired = useCallback((logic: RouteLogic = RouteLogic.PUSH) => {
|
||||
return navigate('/expired', {
|
||||
replace: logic === RouteLogic.REPLACE,
|
||||
});
|
||||
}, []);
|
||||
const jumpToSignIn = useCallback(
|
||||
(
|
||||
logic: RouteLogic = RouteLogic.PUSH,
|
||||
@@ -157,7 +150,7 @@ export function useNavigateHelper() {
|
||||
...otherOptions,
|
||||
});
|
||||
},
|
||||
[navigate]
|
||||
[]
|
||||
);
|
||||
|
||||
return useMemo(
|
||||
|
||||
Reference in New Issue
Block a user