fix: uncaughtException: this.getWorkspacesAsList(...).find is not a function

This commit is contained in:
林一二 2021-11-05 00:40:39 +08:00
parent 41c08582d4
commit 57ce9cc1a4

View file

@ -169,11 +169,20 @@ export class Workspace implements IWorkspaceService {
/**
* Get sorted workspace list
* Async so proxy type is async
*/
public async getWorkspacesAsList(): Promise<IWorkspace[]> {
return Object.values(this.workspaces).sort((a, b) => a.order - b.order);
}
/**
* Get sorted workspace list
* Sync for internal use
*/
private getWorkspacesAsListSync(): IWorkspace[] {
return Object.values(this.workspaces).sort((a, b) => a.order - b.order);
}
public async get(id: string): Promise<IWorkspace | undefined> {
return this.workspaces[id];
}
@ -216,7 +225,7 @@ export class Workspace implements IWorkspaceService {
// we add mainWikiID in creation, we fix this value for old existed workspaces
// eslint-disable-next-line @typescript-eslint/strict-boolean-expressions
if (workspaceToSanitize.isSubWiki && !workspaceToSanitize.mainWikiID) {
const mainWorkspace = (this.getWorkspacesAsList() as unknown as IWorkspace[]).find(
const mainWorkspace = (this.getWorkspacesAsListSync() ?? []).find(
(workspaceToSearch) => workspaceToSanitize.mainWikiToLink === workspaceToSearch.wikiFolderLocation,
);
if (mainWorkspace !== undefined) {