fix: make remove workspace logic correct

This commit is contained in:
tzhangchi
2023-02-03 23:57:24 +08:00
parent b102e234e3
commit 9a315ed994

View File

@@ -109,17 +109,17 @@ export class AffineProvider extends BaseProvider {
this._logger('receive server message'); this._logger('receive server message');
const newlyCreatedWorkspaces: WorkspaceUnit[] = []; const newlyCreatedWorkspaces: WorkspaceUnit[] = [];
const currentWorkspaceIds = this._workspaces.list().map(w => w.id); const currentWorkspaceIds = this._workspaces.list().map(w => w.id);
const newlyRemoveWorkspaceIds = []; const newlyRemovedWorkspacecIds = currentWorkspaceIds;
for (const [id, detail] of Object.entries(ws_details)) { for (const [id, detail] of Object.entries(ws_details)) {
const { name, avatar } = metadata[id]; const { name, avatar } = metadata[id];
/** /**
* collect the workspaces that need to be removed in the context * collect the workspaces that need to be removed in the context
*/ */
const ifWorkspaceNotExists = currentWorkspaceIds.indexOf(id) < 0; const workspaceIndex = currentWorkspaceIds.indexOf(id);
if (ifWorkspaceNotExists) { const ifWorkspaceExist = workspaceIndex !== -1;
newlyRemoveWorkspaceIds.push(id); if (ifWorkspaceExist) {
newlyRemovedWorkspacecIds.splice(workspaceIndex, 1);
} }
/** /**
@@ -159,7 +159,7 @@ export class AffineProvider extends BaseProvider {
this._workspaces.add(newlyCreatedWorkspaces); this._workspaces.add(newlyCreatedWorkspaces);
// sync newlyRemoveWorkspaces to context // sync newlyRemoveWorkspaces to context
this._workspaces.remove(newlyRemoveWorkspaceIds); this._workspaces.remove(newlyRemovedWorkspacecIds);
} }
private _getWebsocketProvider(workspace: BlocksuiteWorkspace) { private _getWebsocketProvider(workspace: BlocksuiteWorkspace) {