diff --git a/gdn-app/src/components/CNote.vue b/gdn-app/src/components/CNote.vue
index e0a9918..61c1bdb 100644
--- a/gdn-app/src/components/CNote.vue
+++ b/gdn-app/src/components/CNote.vue
@@ -1,13 +1,15 @@
+
diff --git a/gdn-app/src/stores/ui.ts b/gdn-app/src/stores/ui.ts
index 81f4764..91cdad7 100644
--- a/gdn-app/src/stores/ui.ts
+++ b/gdn-app/src/stores/ui.ts
@@ -1,4 +1,4 @@
-import { pathAncestors, pathLiesOn } from "@/util";
+import { pathAncestors, pathLiesOn, pathSlice } from "@/util";
import { defineStore } from "pinia";
import { ref, watchEffect } from "vue";
@@ -6,6 +6,7 @@ export const useUiStore = defineStore("ui", () => {
const anchorId = ref();
const focusPath = ref("");
const openPaths = ref>(new Set());
+ const pinned = ref(); // The last two segments of the path
// Ensure all nodes on the focusPath are unfolded.
watchEffect(() => {
@@ -19,27 +20,42 @@ export const useUiStore = defineStore("ui", () => {
return openPaths.value.has(path);
}
- function setOpen(path: string, open: boolean) {
+ function setOpen(path: string, value: boolean) {
// Move the focusPath if necessary
- if (!open && isOpen(path) && pathLiesOn(path, focusPath.value)) {
+ if (!value && isOpen(path) && pathLiesOn(path, focusPath.value)) {
focusPath.value = path;
}
// Don't update openPaths unnecessarily.
// Just in case vue itself doesn't debounce Set operations.
- if (open && !isOpen(path)) openPaths.value.add(path);
- else if (!open && isOpen(path)) openPaths.value.delete(path);
+ if (value && !isOpen(path)) openPaths.value.add(path);
+ else if (!value && isOpen(path)) openPaths.value.delete(path);
}
function toggleOpen(path: string) {
setOpen(path, !isOpen(path));
}
+ function isPinned(path: string): boolean {
+ return pathSlice(path, -2) === pinned.value;
+ }
+
+ function setPinned(path: string) {
+ pinned.value = pathSlice(path, -2);
+ }
+
+ function unsetPinned() {
+ pinned.value = undefined;
+ }
+
return {
anchorId,
focusPath,
isOpen,
setOpen,
toggleOpen,
+ isPinned,
+ setPinned,
+ unsetPinned,
};
});
diff --git a/gdn-app/src/util.ts b/gdn-app/src/util.ts
index 794ac90..225f7b6 100644
--- a/gdn-app/src/util.ts
+++ b/gdn-app/src/util.ts
@@ -7,12 +7,16 @@ function pathParse(path: string): string[] {
return path.split("/");
}
+export function pathSlice(path: string, start: number, end?: number): string {
+ return pathString(pathParse(path).slice(start, end));
+}
+
export function pathAppend(path: string, key: string): string {
return pathString(pathParse(path).concat(key));
}
export function pathAncestor(path: string): string {
- return pathString(pathParse(path).slice(0, -1));
+ return pathSlice(path, 0, -1);
}
export function pathAncestors(path: string): string[] {