update active note

This commit is contained in:
2023-05-13 07:29:27 +02:00
parent f96d139b55
commit 9b75843a9d
6 changed files with 19 additions and 15 deletions

View File

@@ -14,17 +14,20 @@ export const notes = computed<Note[]>(() => {
.sort((a, b) => b.modified - a.modified) as Note[]
})
watch(notes, () => {
if (notes.value.length > 0 && !activeNote.value) activeNote.value = rootNote.value
if (notes.value.length > 0 && !activeNote.value) setActiveNote(rootNote.value?.id)
})
export const activeNote = ref<Note>()
const activeNoteId = ref<string>()
export const activeNote = computed(() =>
notes.value.find((note) => note.id === activeNoteId.value)
)
watch(activeNote, () => {
if (activeNote.value) {
useTitle(`${activeNote.value.title} | Contexted`)
}
})
export const setActiveNote = (noteId: string) => {
activeNote.value = notes.value.find((note) => note.id === noteId)
export const setActiveNote = (noteId: string | undefined) => {
if (noteId) activeNoteId.value = noteId
}
export const rootNote = computed<Note | undefined>(() => {
@@ -95,7 +98,7 @@ export const addNote = (title: string, content: string, goToNote: boolean = fals
modified: new Date().getTime(),
}
baseNotes[id] = newNote
if (goToNote) activeNote.value = notes.value.find((note) => note.id === newNote.id)
if (goToNote) setActiveNote(id)
}
export const deleteNote = (noteId: string) => {