fix: dispatch workspace change event (#2261)
This commit is contained in:
@@ -110,10 +110,28 @@ export const rootCurrentWorkspaceAtom = atom<Promise<AllWorkspace>>(
|
|||||||
// we will wait for the necessary providers to be ready
|
// we will wait for the necessary providers to be ready
|
||||||
await provider.whenReady;
|
await provider.whenReady;
|
||||||
}
|
}
|
||||||
|
logger.info('current workspace', workspace);
|
||||||
|
globalThis.currentWorkspace = workspace;
|
||||||
|
globalThis.dispatchEvent(
|
||||||
|
new CustomEvent('affine:workspace:change', {
|
||||||
|
detail: { id: workspace.id },
|
||||||
|
})
|
||||||
|
);
|
||||||
return workspace;
|
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.
|
// Do not add `rootCurrentWorkspacePageAtom`, this is not needed.
|
||||||
// It can be derived from `rootCurrentWorkspaceAtom` and `rootCurrentPageIdAtom`
|
// It can be derived from `rootCurrentWorkspaceAtom` and `rootCurrentPageIdAtom`
|
||||||
|
|
||||||
|
|||||||
@@ -37,7 +37,6 @@ import { useSyncRouterWithCurrentWorkspaceId } from '../hooks/use-sync-router-wi
|
|||||||
import { useWorkspaces } from '../hooks/use-workspaces';
|
import { useWorkspaces } from '../hooks/use-workspaces';
|
||||||
import { WorkspacePlugins } from '../plugins';
|
import { WorkspacePlugins } from '../plugins';
|
||||||
import { ModalProvider } from '../providers/ModalProvider';
|
import { ModalProvider } from '../providers/ModalProvider';
|
||||||
import type { AllWorkspace } from '../shared';
|
|
||||||
import { pathGenerator, publicPathGenerator } from '../shared';
|
import { pathGenerator, publicPathGenerator } from '../shared';
|
||||||
import {
|
import {
|
||||||
MainContainer,
|
MainContainer,
|
||||||
@@ -46,11 +45,6 @@ import {
|
|||||||
StyledToolWrapper,
|
StyledToolWrapper,
|
||||||
} from './styles';
|
} from './styles';
|
||||||
|
|
||||||
declare global {
|
|
||||||
// eslint-disable-next-line no-var
|
|
||||||
var currentWorkspace: AllWorkspace;
|
|
||||||
}
|
|
||||||
|
|
||||||
const QuickSearchModal = lazy(() =>
|
const QuickSearchModal = lazy(() =>
|
||||||
import('../components/pure/quick-search-modal').then(module => ({
|
import('../components/pure/quick-search-modal').then(module => ({
|
||||||
default: module.QuickSearchModal,
|
default: module.QuickSearchModal,
|
||||||
@@ -260,11 +254,6 @@ export const WorkspaceLayoutInner: FC<PropsWithChildren> = ({ children }) => {
|
|||||||
const { jumpToPage } = useRouterHelper(router);
|
const { jumpToPage } = useRouterHelper(router);
|
||||||
const t = useAFFiNEI18N();
|
const t = useAFFiNEI18N();
|
||||||
|
|
||||||
useEffect(() => {
|
|
||||||
logger.info('currentWorkspace: ', currentWorkspace);
|
|
||||||
globalThis.currentWorkspace = currentWorkspace;
|
|
||||||
}, [currentWorkspace]);
|
|
||||||
|
|
||||||
//#region init workspace
|
//#region init workspace
|
||||||
if (currentWorkspace.blockSuiteWorkspace.isEmpty) {
|
if (currentWorkspace.blockSuiteWorkspace.isEmpty) {
|
||||||
// this is a new workspace, so we should redirect to the new page
|
// this is a new workspace, so we should redirect to the new page
|
||||||
|
|||||||
Reference in New Issue
Block a user