fix: public workspace loading (#1144)

This commit is contained in:
Himself65
2023-02-20 20:32:32 -06:00
committed by GitHub
parent 8c492d2a83
commit ed4d1e8bcd
8 changed files with 58 additions and 97 deletions

View File

@@ -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

View File

@@ -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]);
}
};

View File

@@ -4,5 +4,6 @@ export { createDefaultWorkspace, DataCenterPreloader } from './app/datacenter';
export {
dataCenterPromise,
useDataCenter,
useDataCenterPublicWorkspace,
useDataCenterWorkspace,
} from './app/datacenter';