mirror of
https://github.com/toeverything/AFFiNE.git
synced 2026-02-13 12:55:00 +00:00
fix: public workspace loading (#1144)
This commit is contained in:
@@ -129,6 +129,19 @@ export function useDataCenterWorkspace(
|
||||
return data ?? null;
|
||||
}
|
||||
|
||||
export function useDataCenterPublicWorkspace(workspaceId: string | null) {
|
||||
const { data, error } = useSWR<WorkspaceUnit | null>(
|
||||
['datacenter', workspaceId, 'public'],
|
||||
{
|
||||
fallbackData: null,
|
||||
}
|
||||
);
|
||||
return {
|
||||
workspace: data ?? null,
|
||||
error,
|
||||
} as const;
|
||||
}
|
||||
|
||||
export function DataCenterPreloader({ children }: React.PropsWithChildren) {
|
||||
const api = useGlobalStateApi();
|
||||
//# region effect for updating workspace page list
|
||||
|
||||
@@ -84,7 +84,9 @@ export const useGlobalState: UseBoundStore<Store> = ((
|
||||
// eslint-disable-next-line @typescript-eslint/no-explicit-any
|
||||
}) as any;
|
||||
|
||||
export type DataKey = ['datacenter', string | null] | ['datacenter'];
|
||||
export type DataKey =
|
||||
| ['datacenter', string | null, 'public' | undefined]
|
||||
| ['datacenter'];
|
||||
|
||||
const swrFetcher = async (keys: DataKey) => {
|
||||
assertEquals(keys[0], 'datacenter');
|
||||
@@ -100,6 +102,9 @@ const swrFetcher = async (keys: DataKey) => {
|
||||
return null;
|
||||
}
|
||||
const dataCenter = await dataCenterPromise;
|
||||
if (keys[2] === 'public') {
|
||||
return dataCenter.loadPublicWorkspace(keys[1]);
|
||||
}
|
||||
return dataCenter.loadWorkspace(keys[1]);
|
||||
}
|
||||
};
|
||||
|
||||
@@ -4,5 +4,6 @@ export { createDefaultWorkspace, DataCenterPreloader } from './app/datacenter';
|
||||
export {
|
||||
dataCenterPromise,
|
||||
useDataCenter,
|
||||
useDataCenterPublicWorkspace,
|
||||
useDataCenterWorkspace,
|
||||
} from './app/datacenter';
|
||||
|
||||
Reference in New Issue
Block a user