fix: dispatch workspace change event (#2261)

This commit is contained in:
Himself65
2023-05-08 14:47:47 +08:00
committed by GitHub
parent a942add87a
commit f1c3d575ad
2 changed files with 18 additions and 11 deletions
+18
View File
@@ -110,10 +110,28 @@ export const rootCurrentWorkspaceAtom = atom<Promise<AllWorkspace>>(
// we will wait for the necessary providers to be ready
await provider.whenReady;
}
logger.info('current workspace', workspace);
globalThis.currentWorkspace = workspace;
globalThis.dispatchEvent(
new CustomEvent('affine:workspace:change', {
detail: { id: workspace.id },
})
);
return workspace;
}
);
declare global {
/**
* @internal debug only
*/
// eslint-disable-next-line no-var
var currentWorkspace: AllWorkspace | undefined;
interface WindowEventMap {
'affine:workspace:change': CustomEvent<{ id: string }>;
}
}
// Do not add `rootCurrentWorkspacePageAtom`, this is not needed.
// It can be derived from `rootCurrentWorkspaceAtom` and `rootCurrentPageIdAtom`