update active note
This commit is contained in:
@@ -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) => {
|
||||
|
||||
Reference in New Issue
Block a user