This commit is contained in:
2023-04-27 12:09:14 +02:00
parent 3579a5894a
commit 552cd7269b
15 changed files with 392 additions and 47 deletions

View File

@@ -1,15 +1,30 @@
import { ref } from 'vue'
const notes = ref<Note[]>([])
import { ref, computed, watch } from 'vue'
import { useTitle } from '@vueuse/core'
export default function useNotes() {
const setDefaultNotes = (defaultNotes: Note[]) => {
notes.value = defaultNotes.map((note) => ({
export const notes = ref<Note[]>([])
export const activeNote = ref<Note>()
watch(activeNote, () => {
if (activeNote.value) useTitle(`${activeNote.value.title} | Contexted`)
})
export const rootNote = computed<Note | undefined>(() =>
notes.value.find((note: Note) => note.isRoot)
)
watch(
rootNote,
() => {
if (rootNote.value) activeNote.value = rootNote.value
},
{ immediate: true }
)
export const setDefaultNotes = (defaultNotes: Note[]) => {
notes.value = defaultNotes.map(
(note): Note => ({
...note,
created: new Date().getTime(),
modified: new Date().getTime(),
}))
}
const rootNote = notes.value.find((note) => note.isRoot)
return { notes, setDefaultNotes, rootNote }
})
)
}