diff --git a/src/components/QuickEntry.tsx b/src/components/QuickEntry.tsx index c9e3b81..5ca31b3 100644 --- a/src/components/QuickEntry.tsx +++ b/src/components/QuickEntry.tsx @@ -1,5 +1,5 @@ -import { type Component, createSignal, createMemo, onCleanup, onMount } from "solid-js"; -import { store, currentTaskContext } from "@/store"; +import { type Component, createSignal, onCleanup, onMount } from "solid-js"; +import { store } from "@/store"; import { Plus, X } from "lucide-solid"; import { Button } from "@/components/ui/button"; import { cn } from "@/lib/utils"; @@ -7,37 +7,6 @@ import { QuickEntryForm } from "./QuickEntryForm"; export const QuickEntry: Component = () => { const [isOpen, setIsOpen] = createSignal(false); - // Autofill tags based on context when opening - const initialTags = createMemo(() => { - if (!isOpen()) return []; - - const tags: string[] = []; - const ctx = currentTaskContext(); - - if (store.isNotepadMode) { - // Not in a specific context, but in Notes mode. - // We use global window variable set by Layout to get the active note id - const activeNoteId = (window as any)._activeNoteId; - if (activeNoteId) { - const note = store.notes.find(n => n.id === activeNoteId); - if (note && note.title) { - const noteTagName = note.title.trim(); - if (noteTagName) tags.push(noteTagName); - } - } - } else if (typeof ctx === 'object') { - if ('bucketId' in ctx) { - // Bucket View: Autofill bucket name - const bucketName = ctx.name; - if (bucketName) tags.push(`@${bucketName}`); - } else if ('userId' in ctx) { - // Shared User View: Autofill user name (assuming name IS the tag for sharing) - const userName = ctx.name; - if (userName) tags.push(`@${userName}`); - } - } - return tags; - }); const handleKeyDown = (e: KeyboardEvent) => { if ((e.metaKey || e.ctrlKey) && e.key === "k") { @@ -66,10 +35,10 @@ export const QuickEntry: Component = () => { {isOpen() && ( -
+
setIsOpen(false)} /> -
+
diff --git a/src/components/QuickEntryForm.tsx b/src/components/QuickEntryForm.tsx index e881fa3..9c9eed3 100644 --- a/src/components/QuickEntryForm.tsx +++ b/src/components/QuickEntryForm.tsx @@ -1,6 +1,6 @@ import { type Component, createSignal, createEffect, onMount, For, Show, Suspense, lazy } from "solid-js"; -import { addTask, calculateDateFromUrgency, calculateUrgencyFromDate, store, upsertTagDefinition, type TaskTemplate } from "@/store"; -import { Search, Command, Clock, ArrowUpCircle, Copy, ChevronDown, Gauge } from "lucide-solid"; +import { addTask, calculateDateFromUrgency, calculateUrgencyFromDate, store, upsertTagDefinition, type TaskTemplate, currentTaskContext } from "@/store"; +import { Search, Command, Clock, ArrowUpCircle, Copy, ChevronDown, Gauge, RotateCcw } from "lucide-solid"; import { Button } from "@/components/ui/button"; import { Badge } from "@/components/ui/badge"; import { TextField, TextFieldInput } from "@/components/ui/textfield"; @@ -21,19 +21,32 @@ interface QuickEntryFormProps { initialTags?: string[]; } +// Global state for QuickEntry persistence +const [input, setInput] = createSignal(""); +const [priority, setPriority] = createSignal(""); +const [urgency, setUrgency] = createSignal(""); +const [tags, setTags] = createSignal([]); +const [description, setDescription] = createSignal(""); +const [size, setSize] = createSignal("3"); +const [dateString, setDateString] = createSignal(""); + +let lastParsedTags: string[] = []; + +const resetQuickEntryState = () => { + setInput(""); + setPriority(""); + setUrgency(""); + setTags([]); + setDescription(""); + setSize("3"); + setDateString(""); + lastParsedTags = []; +}; + export const QuickEntryForm: Component = (props) => { const { resolvedTheme } = useTheme(); - // Diff tracking for reactive tags - let lastParsedTags: string[] = []; - const [input, setInput] = createSignal(props.initialTitle || ""); - const [priority, setPriority] = createSignal(""); - const [urgency, setUrgency] = createSignal(""); - const [tags, setTags] = createSignal(props.initialTags || []); - const [description, setDescription] = createSignal(""); const [editorInstance, setEditorInstance] = createSignal(null); - const [size, setSize] = createSignal("3"); - const [dateString, setDateString] = createSignal(""); let inputRef: HTMLInputElement | undefined; @@ -41,6 +54,9 @@ export const QuickEntryForm: Component = (props) => { if (props.autoFocus) { setTimeout(() => inputRef?.focus(), 100); } + if (props.initialTitle && !input()) { + setInput(props.initialTitle); + } }); // Reactive sync from props (handles context changes while open) @@ -187,6 +203,33 @@ export const QuickEntryForm: Component = (props) => { finalDueDate = new Date(dateStr); } + // Apply context tags at the time of creation + const ctx = currentTaskContext(); + if (store.isNotepadMode) { + const activeNoteId = (window as any)._activeNoteId; + if (activeNoteId) { + const note = store.notes.find(n => n.id === activeNoteId); + if (note && note.title) { + const noteTagName = note.title.trim(); + if (noteTagName && !finalTags.includes(noteTagName)) finalTags.push(noteTagName); + } + } + } else if (typeof ctx === 'object') { + if ('bucketId' in ctx) { + const bucketName = ctx.name; + if (bucketName) { + const tag = `@${bucketName}`; + if (!finalTags.includes(tag)) finalTags.push(tag); + } + } else if ('userId' in ctx) { + const userName = ctx.name; + if (userName) { + const tag = `@${userName}`; + if (!finalTags.includes(tag)) finalTags.push(tag); + } + } + } + addTask(title.replace(/\s+/g, " ").trim(), { priority: finalPriority, dueDate: finalDueDate || undefined, @@ -195,14 +238,7 @@ export const QuickEntryForm: Component = (props) => { size: parseInt(size()) }); - setInput(""); - setPriority(""); - setUrgency(""); - setTags([]); - setDescription(""); - setSize("3"); - lastParsedTags = []; - setDateString(""); + resetQuickEntryState(); const instance = editorInstance(); if (instance) instance.commands.setContent(""); @@ -420,6 +456,18 @@ export const QuickEntryForm: Component = (props) => {
+ 0}>