diff --git a/packages/data-center/src/datacenter.ts b/packages/data-center/src/datacenter.ts index 1221b114f3..4b58662382 100644 --- a/packages/data-center/src/datacenter.ts +++ b/packages/data-center/src/datacenter.ts @@ -100,7 +100,8 @@ export class DataCenter { const workspace = createBlocksuiteWorkspace(workspaceMeta.id); await this._mainProvider.createWorkspace(workspace, workspaceMeta); - return workspace; + const workspaceUnit = this._workspaceUnitCollection.find(workspaceMeta.id); + return workspaceUnit; } /** @@ -154,18 +155,23 @@ export class DataCenter { * @returns {Promise} */ public async loadWorkspace(workspaceId: string) { - const workspaceInfo = this._workspaceUnitCollection.find(workspaceId); - assert(workspaceInfo, 'Workspace not found'); - const currentProvider = this.providerMap.get(workspaceInfo.provider); + const workspaceUnit = this._workspaceUnitCollection.find(workspaceId); + assert(workspaceUnit, 'Workspace not found'); + const currentProvider = this.providerMap.get(workspaceUnit.provider); if (currentProvider) { currentProvider.closeWorkspace(workspaceId); } - const provider = this.providerMap.get(workspaceInfo.provider); - assert(provider, `provide '${workspaceInfo.provider}' is not registered`); - this._logger(`Loading ${workspaceInfo.provider} workspace: `, workspaceId); + const provider = this.providerMap.get(workspaceUnit.provider); + assert(provider, `provide '${workspaceUnit.provider}' is not registered`); + this._logger(`Loading ${workspaceUnit.provider} workspace: `, workspaceId); const workspace = this._getBlocksuiteWorkspace(workspaceId); this._workspaceInstances.set(workspaceId, workspace); - return await provider.warpWorkspace(workspace); + await provider.warpWorkspace(workspace); + this._workspaceUnitCollection.workspaces.forEach(workspaceUnit => { + workspaceUnit.setBlocksuiteWorkspace(null); + }); + workspaceUnit.setBlocksuiteWorkspace(workspace); + return workspaceUnit; } /** diff --git a/packages/data-center/src/workspace-unit.ts b/packages/data-center/src/workspace-unit.ts index 527e8647ef..4069b4200a 100644 --- a/packages/data-center/src/workspace-unit.ts +++ b/packages/data-center/src/workspace-unit.ts @@ -30,7 +30,7 @@ export class WorkspaceUnit { public provider!: string; public syncMode: 'all' | 'core' = 'core'; - private _blocksuiteWorkspace?: BlocksuiteWorkspace; + private _blocksuiteWorkspace?: BlocksuiteWorkspace | null; constructor(params: WorkspaceUnitCtorParams) { this.id = params.id; @@ -41,7 +41,7 @@ export class WorkspaceUnit { return this._blocksuiteWorkspace; } - setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace) { + setBlocksuiteWorkspace(blocksuiteWorkspace: BlocksuiteWorkspace | null) { if (blocksuiteWorkspace?.room !== this.id) { throw new Error('Workspace id inconsistent.'); }