Unlink and delete notes

This commit is contained in:
Joscha 2025-02-12 13:20:56 +01:00
parent da74fa9261
commit 815e88cf18
2 changed files with 26 additions and 4 deletions

View file

@ -12,6 +12,7 @@ import {
RiCornerUpRightLine, RiCornerUpRightLine,
RiDeleteBinLine, RiDeleteBinLine,
RiEditLine, RiEditLine,
RiLinkUnlinkM,
RiPushpinFill, RiPushpinFill,
RiPushpinLine, RiPushpinLine,
} from "@remixicon/vue"; } from "@remixicon/vue";
@ -83,6 +84,15 @@ function onClick(): void {
ui.toggleOpen(path); ui.toggleOpen(path);
} }
function onDeleteButtonClick(): void {
notes.deleteNote(segment.id);
}
function onUnlinkButtonClick(): void {
if (parentId === undefined) return;
notes.removeChild(parentId, segment);
}
function onEditButtonClick(): void { function onEditButtonClick(): void {
if (!note.value) return; if (!note.value) return;
ui.edit(path); ui.edit(path);
@ -208,9 +218,12 @@ function onInsertEditorCopy(): void {
<!-- Controls --> <!-- Controls -->
<div v-show="!editing" class="absolute right-0 flex h-6 items-center gap-0.5"> <div v-show="!editing" class="absolute right-0 flex h-6 items-center gap-0.5">
<CNoteButton :visible="hovering"> <CNoteButton :visible="hovering" @click.stop="onDeleteButtonClick">
<RiDeleteBinLine size="16px" /> <RiDeleteBinLine size="16px" />
</CNoteButton> </CNoteButton>
<CNoteButton :visible="hovering" @click.stop="onUnlinkButtonClick">
<RiLinkUnlinkM size="16px" />
</CNoteButton>
<CNoteButton :visible="hovering" @click.stop="onEditButtonClick"> <CNoteButton :visible="hovering" @click.stop="onEditButtonClick">
<RiEditLine size="16px" /> <RiEditLine size="16px" />
</CNoteButton> </CNoteButton>

View file

@ -38,8 +38,12 @@ export const useNotesStore = defineStore("notes", () => {
return notes.value.get(id)!; // Re-getting so returned Note is reactive return notes.value.get(id)!; // Re-getting so returned Note is reactive
} }
function clearNotes(): void { function deleteNote(id: string): void {
notes.value.clear(); for (const note of notes.value.values()) {
note.children = note.children.filter((it) => it !== id);
}
notes.value.delete(id);
} }
function addChild(id: string, childId: string, index: number): void { function addChild(id: string, childId: string, index: number): void {
@ -83,13 +87,18 @@ export const useNotesStore = defineStore("notes", () => {
to.children.splice(toIndex, 0, segment.id); to.children.splice(toIndex, 0, segment.id);
} }
function clearNotes(): void {
notes.value.clear();
}
return { return {
getNote, getNote,
getParents, getParents,
createNote, createNote,
clearNotes, deleteNote,
addChild, addChild,
removeChild, removeChild,
moveChild, moveChild,
clearNotes,
}; };
}); });