create note on click if does not exist

This commit is contained in:
2023-05-17 03:47:48 +02:00
parent add3e944f6
commit 8774d74163
2 changed files with 6 additions and 3 deletions

View File

@@ -13,7 +13,7 @@ import ListPlugin from '@ckeditor/ckeditor5-list/src/list'
import AutoformatPlugin from '@ckeditor/ckeditor5-autoformat/src/autoformat'
import ContextedPlugin from '@/ckeditor/ContextedPlugin'
import { mdToHtml, htmlToMd } from '@/utils/markdown'
import { getNoteByTitle, setActiveNote } from '@/composables/useNotes'
import { getNoteByTitle, setActiveNote, addNote } from '@/composables/useNotes'
import Autocomplete from '@/components/Autocomplete.vue'
const props = defineProps<{ note: Note }>()
@@ -62,9 +62,11 @@ watch(editorData, () => emit('update', htmlToMd(editorData.value)))
let editorInstance: any
const handleClick = ({ data }: { data: any }) => {
if (!data.domTarget.hasAttribute('data-contexted-link')) return
const noteTitle = data.domTarget.textContent as string
const note = getNoteByTitle(noteTitle)
if (note) setActiveNote(note.id)
let note: BaseNote | Note | undefined = getNoteByTitle(noteTitle)
if (!note) note = addNote(noteTitle, '')
setActiveNote(note.id)
}
const autocompleteRef = ref<InstanceType<typeof Autocomplete> | null>(null)

View File

@@ -104,6 +104,7 @@ export const addNote = (title: string, content: string, goToNote: boolean = fals
}
baseNotes[id] = newNote
if (goToNote) setActiveNote(id)
return newNote
}
export const deleteNote = (noteId: string) => {