mirror of
https://github.com/toeverything/AFFiNE.git
synced 2025-01-02 14:27:19 +03:00
feat: add clear all workspaces
This commit is contained in:
parent
d154a28ad1
commit
512c0a791e
@ -279,6 +279,16 @@ export class DataCenter {
|
||||
return await this._transWorkspaceProvider(workspace, 'affine');
|
||||
}
|
||||
|
||||
/**
|
||||
* @deprecated
|
||||
* clear all workspaces and data
|
||||
*/
|
||||
public async clear() {
|
||||
for (const provider of this.providerMap.values()) {
|
||||
await provider.clear();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Select a file to import the workspace
|
||||
* @param {File} file file of workspace.
|
||||
|
@ -185,12 +185,21 @@ export class AffineProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
public override async delete(id: string): Promise<void> {
|
||||
// TODO delete workspace all local data
|
||||
await this.close(id);
|
||||
IndexedDBProvider.delete(id);
|
||||
await deleteWorkspace({ id });
|
||||
}
|
||||
|
||||
public override async clear(): Promise<void> {
|
||||
// TODO: clear all workspaces source
|
||||
for (const w of this._workspacesCache.values()) {
|
||||
if (w.room) {
|
||||
try {
|
||||
await this.delete(w.room);
|
||||
} catch (e) {
|
||||
this._logger('has a problem of delete workspace ', e);
|
||||
}
|
||||
}
|
||||
}
|
||||
this._workspacesCache.clear();
|
||||
}
|
||||
|
||||
|
@ -38,22 +38,23 @@ export class LocalProvider extends BaseProvider {
|
||||
return workspace;
|
||||
}
|
||||
|
||||
override loadWorkspaces() {
|
||||
override loadWorkspaces(): Promise<WS[]> {
|
||||
const workspaceStr = storage.getItem(WORKSPACE_KEY);
|
||||
let workspaces: WS[] = [];
|
||||
if (workspaceStr) {
|
||||
try {
|
||||
return JSON.parse(workspaceStr);
|
||||
workspaces = JSON.parse(workspaceStr) as WS[];
|
||||
} catch (error) {
|
||||
this._logger(`Failed to parse workspaces from storage`);
|
||||
}
|
||||
}
|
||||
return [];
|
||||
return Promise.resolve(workspaces);
|
||||
}
|
||||
|
||||
public override async delete(id: string): Promise<void> {
|
||||
const index = this._workspacesList.findIndex(ws => ws.id === id);
|
||||
if (index !== -1) {
|
||||
// TODO delete workspace all data
|
||||
IndexedDBProvider.delete(id);
|
||||
this._workspacesList.splice(index, 1);
|
||||
this._storeWorkspaces(this._workspacesList);
|
||||
} else {
|
||||
@ -75,7 +76,8 @@ export class LocalProvider extends BaseProvider {
|
||||
}
|
||||
|
||||
public override async clear(): Promise<void> {
|
||||
// TODO: clear all data
|
||||
const workspaces = await this.loadWorkspaces();
|
||||
workspaces.forEach(ws => IndexedDBProvider.delete(ws.id));
|
||||
this._storeWorkspaces([]);
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user