diff --git a/frontend/src/components/QuickAdd.vue b/frontend/src/components/QuickAdd.vue index bac9092..7fa3724 100644 --- a/frontend/src/components/QuickAdd.vue +++ b/frontend/src/components/QuickAdd.vue @@ -4,6 +4,8 @@ import { useNotesStore } from "../stores/notes"; import ColorPicker from "./ColorPicker.vue"; import type { NoteColor } from "../notes/colors"; +const props = withDefaults(defineProps<{ autofocus?: boolean }>(), { autofocus: false }); + const notes = useNotesStore(); const expanded = ref(false); @@ -20,24 +22,41 @@ async function open() { bodyInput.value?.focus(); } -function reset() { - expanded.value = false; +function hasContent(): boolean { + return title.value.trim() !== "" || body.value.trim() !== ""; +} + +function clearFields() { title.value = ""; body.value = ""; color.value = "default"; } -async function commit() { - const hasContent = title.value.trim() !== "" || body.value.trim() !== ""; - if (hasContent) { - saving.value = true; - try { - await notes.create({ title: title.value, body: body.value, color: color.value }); - } finally { - saving.value = false; - } +async function persist(): Promise { + if (!hasContent()) return; + saving.value = true; + try { + await notes.create({ title: title.value, body: body.value, color: color.value }); + } finally { + saving.value = false; } - reset(); +} + +// Close the composer, saving anything typed. +async function commit() { + await persist(); + clearFields(); + expanded.value = false; +} + +// Shift+Enter: save the current note and immediately start a fresh one, staying +// open + focused for rapid-fire capture. +async function commitAndContinue() { + if (!hasContent()) return; + await persist(); + clearFields(); + await nextTick(); + bodyInput.value?.focus(); } function onDocumentMousedown(e: MouseEvent) { @@ -46,7 +65,11 @@ function onDocumentMousedown(e: MouseEvent) { } } -onMounted(() => document.addEventListener("mousedown", onDocumentMousedown)); +onMounted(() => { + document.addEventListener("mousedown", onDocumentMousedown); + // Landing on the board drops the cursor straight into the note input. + if (props.autofocus) void open(); +}); onBeforeUnmount(() => document.removeEventListener("mousedown", onDocumentMousedown)); @@ -68,14 +91,16 @@ onBeforeUnmount(() => document.removeEventListener("mousedown", onDocumentMoused type="text" placeholder="Title" class="w-full bg-transparent px-1 text-sm font-semibold outline-none placeholder:text-neutral-400" - @keydown.enter.prevent="bodyInput?.focus()" + @keydown.enter.shift.prevent="commitAndContinue" + @keydown.enter.exact.prevent="bodyInput?.focus()" />