updates
This commit is contained in:
@@ -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 }
|
||||
})
|
||||
)
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user