reserve entered paths on navigating back

- retain the list of entered folders on going up the directory tree. 😹
This commit is contained in:
geoffrey45
2022-06-08 15:54:51 +03:00
parent 84bf467d9f
commit 14364a1257
4 changed files with 60 additions and 14 deletions
+3 -3
View File
@@ -43,15 +43,15 @@ function useSubRoutes() {
(newRoute: string) => { (newRoute: string) => {
switch (newRoute) { switch (newRoute) {
case Routes.folder: case Routes.folder:
console.log(newRoute); let oldpath = "";
subPaths.value = createSubPaths(route.params.path); [oldpath, subPaths.value] = createSubPaths(route.params.path, oldpath);
watch( watch(
() => route.params.path, () => route.params.path,
(newPath) => { (newPath) => {
if (newPath == undefined) return; if (newPath == undefined) return;
subPaths.value = createSubPaths(newPath); [oldpath, subPaths.value] = createSubPaths(newPath, oldpath);
} }
); );
break; break;
+10 -2
View File
@@ -2,7 +2,6 @@
<div id="folder-nav-title"> <div id="folder-nav-title">
<div <div
class="folder" class="folder"
v-motion v-motion
:initial="{ :initial="{
opacity: 0, opacity: 0,
@@ -19,7 +18,12 @@
<div class="fname"> <div class="fname">
<div class="icon image"></div> <div class="icon image"></div>
<div class="paths"> <div class="paths">
<div class="path" v-for="path in subPaths" :key="path.path"> <div
class="path"
v-for="path in subPaths"
:key="path.path"
:class="{ current: path.active }"
>
<span class="text">{{ path.name }}</span> <span class="text">{{ path.name }}</span>
</div> </div>
</div> </div>
@@ -120,6 +124,10 @@ defineProps<{
} }
} }
} }
.current > .text {
background-color: $accent;
}
} }
} }
} }
+46 -9
View File
@@ -2,16 +2,53 @@ import { subPath } from "@/interfaces";
/** /**
* Breaks a path into sub-paths. * Breaks a path into sub-paths.
* @param {string} paths to break into subpaths * @param {string} newpath the new path to break into sub-paths.
* @returns {subPath[]} an array of subpaths * @param {string} oldpath the old path to compare with the new path.
*/ */
export default function createSubPaths(paths: string | string[]): subPath[] { export default function createSubPaths(
const pathlist = (paths as string).split("/"); newpath: string | string[],
pathlist.shift(); oldpath: string | string[]
): [string, subPath[]] {
if (oldpath === undefined) oldpath = "";
const subPaths = pathlist.map((path, index) => { newpath = newpath as string;
return { name: path, path: pathlist.slice(0, index + 1).join("/") }; oldpath = oldpath as string;
});
return subPaths; const newlist = newpath.split("/");
newlist.shift();
if (oldpath.includes(newpath)) {
const oldlist = oldpath.split("/");
oldlist.shift();
const current = newlist.slice(-1)[0];
return [oldpath, createSubs(oldlist, current)];
} else {
const current = newlist.slice(-1)[0];
return [newpath, createSubs(newlist, current)];
}
function createSubs(list: string[], current: string) {
const paths = list.map((path, index) => {
return {
active: false,
name: path,
path: newlist.slice(0, index + 1).join("/"),
};
});
paths.reverse();
for (let i = 0; i < paths.length; i++) {
if (paths[i].name === current) {
paths[i].active = true;
break;
}
}
return paths.reverse();
}
} }
// function that takes 2 strings as parameters and returns a string
// that is the concatenation of the two strings
+1
View File
@@ -89,6 +89,7 @@ interface fromSearch {
interface subPath { interface subPath {
name: string; name: string;
path: string; path: string;
active: boolean;
} }
export { export {