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,
RiDeleteBinLine,
RiEditLine,
RiLinkUnlinkM,
RiPushpinFill,
RiPushpinLine,
} from "@remixicon/vue";
@ -83,6 +84,15 @@ function onClick(): void {
ui.toggleOpen(path);
}
function onDeleteButtonClick(): void {
notes.deleteNote(segment.id);
}
function onUnlinkButtonClick(): void {
if (parentId === undefined) return;
notes.removeChild(parentId, segment);
}
function onEditButtonClick(): void {
if (!note.value) return;
ui.edit(path);
@ -208,9 +218,12 @@ function onInsertEditorCopy(): void {
<!-- Controls -->
<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" />
</CNoteButton>
<CNoteButton :visible="hovering" @click.stop="onUnlinkButtonClick">
<RiLinkUnlinkM size="16px" />
</CNoteButton>
<CNoteButton :visible="hovering" @click.stop="onEditButtonClick">
<RiEditLine size="16px" />
</CNoteButton>

View file

@ -38,8 +38,12 @@ export const useNotesStore = defineStore("notes", () => {
return notes.value.get(id)!; // Re-getting so returned Note is reactive
}
function clearNotes(): void {
notes.value.clear();
function deleteNote(id: string): void {
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 {
@ -83,13 +87,18 @@ export const useNotesStore = defineStore("notes", () => {
to.children.splice(toIndex, 0, segment.id);
}
function clearNotes(): void {
notes.value.clear();
}
return {
getNote,
getParents,
createNote,
clearNotes,
deleteNote,
addChild,
removeChild,
moveChild,
clearNotes,
};
});