-
+
const emit = defineEmits<{
- delete: []
- setRoot: []
+ delete: [close: () => void]
+ setRoot: [close: () => void]
}>()
@@ -18,9 +18,9 @@ const emit = defineEmits<{
- Are you sure you want to delete this?
+ Are you sure you want to delete this note?
-
-
+
Set current note as root
Close
diff --git a/src/composables/useNotes.ts b/src/composables/useNotes.ts
index 893cb2d..f872d69 100644
--- a/src/composables/useNotes.ts
+++ b/src/composables/useNotes.ts
@@ -19,12 +19,28 @@ watch(notes, () => {
export const activeNote = ref()
watch(activeNote, () => {
- if (activeNote.value) useTitle(`${activeNote.value.title} | Contexted`)
+ if (activeNote.value) {
+ useTitle(`${activeNote.value.title} | Contexted`)
+ }
+})
+export const setActiveNote = (noteId: string) => {
+ activeNote.value = notes.value.find((note) => note.id === noteId)
+}
+
+export const rootNote = computed(() => {
+ const rootNote = notes.value.find((note: Note) => note.isRoot)
+ return rootNote
})
-export const rootNote = computed(() =>
- notes.value.find((note: Note) => note.isRoot)
-)
+export const setRootNote = (noteId: string) => {
+ if (rootNote.value) {
+ const updatedRootNote = { ...baseNotes[rootNote.value.id], isRoot: false }
+ updateNote(updatedRootNote.id, updatedRootNote)
+ }
+ const note = { ...baseNotes[noteId], isRoot: true }
+ updateNote(noteId, note)
+ setActiveNote(noteId)
+}
export const setDefaultNotes = (defaultNotes: BaseNote[]) => {
defaultNotes.forEach((defaultNote) => {
@@ -61,8 +77,8 @@ export const findNotes = (query: string): Note[] => {
})
}
-export const updateNote = (noteId: string, note: Note) => {
- const updatedNote: Note = {
+export const updateNote = (noteId: string, note: BaseNote) => {
+ const updatedNote: BaseNote = {
...note,
modified: new Date().getTime(),
}
@@ -82,6 +98,10 @@ export const addNote = (title: string, content: string, goToNote: boolean = fals
if (goToNote) activeNote.value = notes.value.find((note) => note.id === newNote.id)
}
+export const deleteNote = (noteId: string) => {
+ delete baseNotes[noteId]
+}
+
const getNoteLinksByNoteId = (noteId: string): string[] => {
const note = baseNotes[noteId]
const regex = /\[\[(.*?)\]\]/g