From 91d9efba77c7e21bdecfdd2fa228af8763a3b0fd Mon Sep 17 00:00:00 2001 From: Sylvia Chen <45579799+sylviacx@users.noreply.github.com> Date: Wed, 16 Oct 2024 11:59:06 -0700 Subject: [PATCH] fix(birdie): breadcrumb navigation selects files (#328) * fix(birdie): breadcrumb navigation selects files * fix(birdie): wording changes --- birdie/src/routes/+page.svelte | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/birdie/src/routes/+page.svelte b/birdie/src/routes/+page.svelte index cfc76ef..5b3fe5b 100644 --- a/birdie/src/routes/+page.svelte +++ b/birdie/src/routes/+page.svelte @@ -429,7 +429,10 @@ const goBack = async (index: number) => { ancestry = ancestry.slice(0, index + 1); $currentRoot = ancestry.join('/'); - $selectedFile = null; + + const parentFiles = await getFiles(ancestry.slice(0, index).join('/')); + $selectedFile = parentFiles.find((f) => f.name === ancestry[index]) ?? null; + commits = []; selectedFiles = []; await refreshFiles(); @@ -566,12 +569,12 @@ }); }; - const addCurrentRootToFileTree = async (node: Node, subFolders: string[]): Promise => { + const addSelectedFilePathToFileTree = async (node: Node, subFolders: string[]): Promise => { if (node.value.fileType === FileType.File) return node; const updatedChildFiles = await getFiles(node.value.path); let updatedChildNodes: Node[] = []; if (subFolders.length === 0) { - // we're at the deepest level of the current root + // we're at the deepest subfolder level // update our children and "forget" anything deeper than this updatedChildFiles.forEach((child) => { updatedChildNodes.push({ @@ -601,7 +604,7 @@ updatedChildNodes = await Promise.all( updatedChildNodes.map((child) => { if (child.value.name === subFolders[0]) { - return addCurrentRootToFileTree(child, subFolders.slice(1)); + return addSelectedFilePathToFileTree(child, subFolders.slice(1)); } return child; }) @@ -619,7 +622,7 @@ rootNode.set(parsedFileTree); } if ($selectedFile) { - $rootNode = await addCurrentRootToFileTree(get(rootNode), $selectedFile.path.split('/')); + $rootNode = await addSelectedFilePathToFileTree(get(rootNode), $selectedFile.path.split('/')); } };