mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-14 05:14:54 +00:00
refactor: init hook useRouterTargetWorkspace (#1127)
This commit is contained in:
@@ -116,6 +116,15 @@ export function useDataCenter() {
|
||||
return data as DataCenter;
|
||||
}
|
||||
|
||||
export function useDataCenterWorkspace(
|
||||
workspaceId: string | null
|
||||
): WorkspaceUnit | null {
|
||||
const { data } = useSWR<WorkspaceUnit | null>(['datacenter', workspaceId], {
|
||||
fallbackData: null,
|
||||
});
|
||||
return data ?? null;
|
||||
}
|
||||
|
||||
export function DataCenterPreloader({ children }: React.PropsWithChildren) {
|
||||
const api = useGlobalStateApi();
|
||||
//# region effect for updating workspace page list
|
||||
|
||||
@@ -84,7 +84,7 @@ export const useGlobalState: UseBoundStore<Store> = ((
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
}) as any;
|
||||
|
||||
export type DataKey = ['datacenter', string] | ['datacenter'];
|
||||
export type DataKey = ['datacenter', string | null] | ['datacenter'];
|
||||
|
||||
const swrFetcher = async (keys: DataKey) => {
|
||||
assertEquals(keys[0], 'datacenter');
|
||||
@@ -96,6 +96,9 @@ const swrFetcher = async (keys: DataKey) => {
|
||||
return dataCenter;
|
||||
});
|
||||
} else {
|
||||
if (keys[1] === null) {
|
||||
return null;
|
||||
}
|
||||
const dataCenter = await dataCenterPromise;
|
||||
return dataCenter.loadWorkspace(keys[1]);
|
||||
}
|
||||
|
||||
@@ -1,4 +1,8 @@
|
||||
export * from './app';
|
||||
export type { PageMeta } from './app/datacenter';
|
||||
export { createDefaultWorkspace, DataCenterPreloader } from './app/datacenter';
|
||||
export { dataCenterPromise, useDataCenter } from './app/datacenter';
|
||||
export {
|
||||
dataCenterPromise,
|
||||
useDataCenter,
|
||||
useDataCenterWorkspace,
|
||||
} from './app/datacenter';
|
||||
|
||||
Reference in New Issue
Block a user