Skip to content

Commit

Permalink
fix: refresh button throwing error in replay browser
Browse files Browse the repository at this point in the history
  • Loading branch information
vinceau committed Mar 2, 2022
1 parent 0530133 commit 7c2bf63
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 4 deletions.
4 changes: 3 additions & 1 deletion src/renderer/lib/hooks/useReplays.ts
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,9 @@ export const useReplays = create<StoreState & StoreReducers>((set, get) => ({
if (!folderInitResult.result) {
throw new Error(`Error initializing folder tree`);
}
const selectRootFolderResult = await ipc_selectTreeFolder.renderer!.trigger({ folderPath: rootFolder });
const selectRootFolderResult = await ipc_selectTreeFolder.renderer!.trigger({
folderPath: currentFolder ?? rootFolder,
});
if (!selectRootFolderResult.result) {
throw new Error(`Error loading folder tree for: ${rootFolder}`);
}
Expand Down
10 changes: 7 additions & 3 deletions src/replays/folderTreeService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -15,12 +15,12 @@ export class FolderTreeService {
}

public async select(folder: string): Promise<readonly FolderResult[]> {
const childNode = this._findChild(folder, this.tree);
const childNode = await this._findChild(folder, this.tree);
childNode.subdirectories = await generateSubFolderTree(folder);
return this.tree;
}

private _findChild(folder: string, nodes: readonly FolderResult[]): FolderResult {
private async _findChild(folder: string, nodes: readonly FolderResult[]): Promise<FolderResult> {
const res = nodes.find(({ fullPath }) => fullPath === folder || isSubdirectory(fullPath, folder));
if (!res) {
throw new Error(`Could not find folder ${folder}`);
Expand All @@ -31,14 +31,18 @@ export class FolderTreeService {
return res;
}

// Expand the subdirectories if necessary
if (res.subdirectories.length === 0) {
res.subdirectories = await generateSubFolderTree(res.fullPath);
}

return this._findChild(folder, res.subdirectories);
}
}

/**
* Returns the tree structure of a folder
* @param folder Details including name, and subdirectories
* @param childrenToExpand The name of the subdirectories to expand.
*/
export async function generateSubFolderTree(folder: string): Promise<FolderResult[]> {
console.log(`generating subfolder tree for folder: ${folder}`);
Expand Down

0 comments on commit 7c2bf63

Please sign in to comment.