([]);
const dirty = ref(false);
const saving = ref(false);
const showPreview = ref(false);
@@ -106,6 +108,7 @@ async function fetchTagSuggestions() {
const res = await apiPost<{ suggested_tags: string[] }>("/api/notes/suggest-tags", {
title: title.value,
body: body.value,
+ current_tags: tags.value,
});
suggestedTags.value = res.suggested_tags;
} catch {
@@ -117,7 +120,9 @@ async function fetchTagSuggestions() {
function applyTagSuggestion(tag: string) {
if (appliedTags.value.has(tag)) return;
- body.value = body.value.trimEnd() + `\n#${tag}`;
+ if (!tags.value.includes(tag)) {
+ tags.value = [...tags.value, tag];
+ }
appliedTags.value.add(tag);
markDirty();
}
@@ -130,9 +135,13 @@ function dismissTagSuggestions() {
// Track saved state for dirty detection
let savedTitle = "";
let savedBody = "";
+let savedTags: string[] = [];
function markDirty() {
- dirty.value = title.value !== savedTitle || body.value !== savedBody;
+ dirty.value =
+ title.value !== savedTitle ||
+ body.value !== savedBody ||
+ JSON.stringify(tags.value) !== JSON.stringify(savedTags);
}
function onBodyUpdate(newVal: string) {
@@ -146,8 +155,10 @@ onMounted(async () => {
if (store.currentNote) {
title.value = store.currentNote.title;
body.value = store.currentNote.body;
+ tags.value = [...(store.currentNote.tags || [])];
savedTitle = title.value;
savedBody = body.value;
+ savedTags = [...tags.value];
}
}
});
@@ -160,15 +171,18 @@ async function save() {
await store.updateNote(noteId.value!, {
title: title.value,
body: body.value,
+ tags: tags.value,
});
savedTitle = title.value;
savedBody = body.value;
+ savedTags = [...tags.value];
dirty.value = false;
toast.show("Note saved");
} else {
const note = await store.createNote({
title: title.value,
body: body.value,
+ tags: tags.value,
});
dirty.value = false;
toast.show("Note created");
@@ -209,9 +223,10 @@ async function autoSave() {
if (!isEditing.value || !dirty.value || saving.value) return;
saving.value = true;
try {
- await store.updateNote(noteId.value!, { title: title.value, body: body.value });
+ await store.updateNote(noteId.value!, { title: title.value, body: body.value, tags: tags.value });
savedTitle = title.value;
savedBody = body.value;
+ savedTags = [...tags.value];
dirty.value = false;
toast.show("Auto-saved");
} catch {
@@ -275,6 +290,12 @@ onUnmounted(() => window.removeEventListener("beforeunload", onBeforeUnload));
@input="markDirty"
/>
+
+
+
+