Show other parents of a note
This commit is contained in:
parent
3628fa260b
commit
de6080c3ad
3 changed files with 37 additions and 4 deletions
|
|
@ -26,7 +26,7 @@ function createSomeNotes() {
|
||||||
|
|
||||||
const n1 = mkNote("n1");
|
const n1 = mkNote("n1");
|
||||||
const n2 = mkNote("n2", n2n1.id, n2n2.id, n2n3.id);
|
const n2 = mkNote("n2", n2n1.id, n2n2.id, n2n3.id);
|
||||||
const n3 = mkNote("n3");
|
const n3 = mkNote("n3", n2n1.id);
|
||||||
const n4 = mkNote("n4");
|
const n4 = mkNote("n4");
|
||||||
const n5 = mkNote("n5", "NaN (not a note)");
|
const n5 = mkNote("n5", "NaN (not a note)");
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -6,6 +6,7 @@ import {
|
||||||
RiAddLine,
|
RiAddLine,
|
||||||
RiArrowDownSLine,
|
RiArrowDownSLine,
|
||||||
RiArrowRightSLine,
|
RiArrowRightSLine,
|
||||||
|
RiCornerUpRightLine,
|
||||||
RiEditLine,
|
RiEditLine,
|
||||||
RiStickyNoteAddLine,
|
RiStickyNoteAddLine,
|
||||||
} from "@remixicon/vue";
|
} from "@remixicon/vue";
|
||||||
|
|
@ -18,12 +19,19 @@ const ui = useUiStore();
|
||||||
|
|
||||||
const props = defineProps<{
|
const props = defineProps<{
|
||||||
noteId: string;
|
noteId: string;
|
||||||
|
parentId?: string;
|
||||||
path: string; // From root to here
|
path: string; // From root to here
|
||||||
forceOpen?: boolean;
|
forceOpen?: boolean;
|
||||||
}>();
|
}>();
|
||||||
|
|
||||||
const note = computed(() => notes.getNote(props.noteId));
|
const note = computed(() => notes.getNote(props.noteId));
|
||||||
|
|
||||||
|
const parents = computed(() => {
|
||||||
|
let parents = notes.getParents(props.noteId);
|
||||||
|
if (props.parentId) parents = parents.difference(new Set([props.parentId]));
|
||||||
|
return [...parents].sort().map((id) => ({ id, text: notes.getNote(id)?.text }));
|
||||||
|
});
|
||||||
|
|
||||||
// Our children and their locally unique keys.
|
// Our children and their locally unique keys.
|
||||||
const children = computed(() => {
|
const children = computed(() => {
|
||||||
if (!note.value) return [];
|
if (!note.value) return [];
|
||||||
|
|
@ -117,6 +125,13 @@ function onCreateEditorFinish(text: string) {
|
||||||
|
|
||||||
<template>
|
<template>
|
||||||
<div class="flex flex-col">
|
<div class="flex flex-col">
|
||||||
|
<!-- Parents -->
|
||||||
|
<div v-if="parents.length > 0" class="pt-1">
|
||||||
|
<div v-for="parent of parents" class="pl-6 text-xs text-neutral-400">
|
||||||
|
<RiCornerUpRightLine size="12px" class="inline" /> {{ parent.text }}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
|
||||||
<div
|
<div
|
||||||
class="relative flex min-h-6 pl-1"
|
class="relative flex min-h-6 pl-1"
|
||||||
:class="focused ? 'bg-neutral-200' : hover ? 'bg-neutral-100' : ''"
|
:class="focused ? 'bg-neutral-200' : hover ? 'bg-neutral-100' : ''"
|
||||||
|
|
@ -166,9 +181,10 @@ function onCreateEditorFinish(text: string) {
|
||||||
<!-- Children -->
|
<!-- Children -->
|
||||||
<div v-if="open && children.length > 0" class="flex flex-col pl-2">
|
<div v-if="open && children.length > 0" class="flex flex-col pl-2">
|
||||||
<CNote
|
<CNote
|
||||||
v-for="child in children"
|
v-for="child of children"
|
||||||
:key="child.key"
|
:key="child.key"
|
||||||
:noteId="child.id"
|
:noteId="child.id"
|
||||||
|
:parentId="props.noteId"
|
||||||
:path="pathAppend(path, child.key)"
|
:path="pathAppend(path, child.key)"
|
||||||
/>
|
/>
|
||||||
</div>
|
</div>
|
||||||
|
|
|
||||||
|
|
@ -1,8 +1,8 @@
|
||||||
import { defineStore } from "pinia";
|
import { defineStore } from "pinia";
|
||||||
import { ref } from "vue";
|
import { computed, ref } from "vue";
|
||||||
|
|
||||||
export type Note = {
|
export type Note = {
|
||||||
id: string;
|
readonly id: string;
|
||||||
text: string;
|
text: string;
|
||||||
children: string[];
|
children: string[];
|
||||||
};
|
};
|
||||||
|
|
@ -10,10 +10,26 @@ export type Note = {
|
||||||
export const useNotesStore = defineStore("notes", () => {
|
export const useNotesStore = defineStore("notes", () => {
|
||||||
const notes = ref<Map<string, Note>>(new Map());
|
const notes = ref<Map<string, Note>>(new Map());
|
||||||
|
|
||||||
|
const parents = computed(() => {
|
||||||
|
const result = new Map<string, Set<string>>();
|
||||||
|
for (const note of notes.value.values()) {
|
||||||
|
for (const childId of note.children) {
|
||||||
|
const parents = result.get(childId) || new Set();
|
||||||
|
result.set(childId, parents);
|
||||||
|
parents.add(note.id);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return result;
|
||||||
|
});
|
||||||
|
|
||||||
function getNote(id: string): Note | undefined {
|
function getNote(id: string): Note | undefined {
|
||||||
return notes.value.get(id);
|
return notes.value.get(id);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
function getParents(id: string): ReadonlySet<string> {
|
||||||
|
return parents.value.get(id) || new Set();
|
||||||
|
}
|
||||||
|
|
||||||
function createNote(text: string): Note {
|
function createNote(text: string): Note {
|
||||||
const id = crypto.randomUUID();
|
const id = crypto.randomUUID();
|
||||||
notes.value.set(id, { id, text, children: [] });
|
notes.value.set(id, { id, text, children: [] });
|
||||||
|
|
@ -26,6 +42,7 @@ export const useNotesStore = defineStore("notes", () => {
|
||||||
|
|
||||||
return {
|
return {
|
||||||
getNote,
|
getNote,
|
||||||
|
getParents,
|
||||||
createNote,
|
createNote,
|
||||||
clearNotes,
|
clearNotes,
|
||||||
};
|
};
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue