diff --git a/src/components/QuickEntry.tsx b/src/components/QuickEntry.tsx index f70c768..61cdd35 100644 --- a/src/components/QuickEntry.tsx +++ b/src/components/QuickEntry.tsx @@ -1,4 +1,4 @@ -import { type Component, createSignal, createEffect, onCleanup, onMount } from "solid-js"; +import { type Component, createSignal, createMemo, onCleanup, onMount } from "solid-js"; import { store, currentTaskContext } from "@/store"; import { Plus, X } from "lucide-solid"; import { Button } from "@/components/ui/button"; @@ -7,37 +7,34 @@ import { QuickEntryForm } from "./QuickEntryForm"; export const QuickEntry: Component = () => { const [isOpen, setIsOpen] = createSignal(false); - const [initialTags, setInitialTags] = createSignal([]); - // Autofill tags based on context when opening - createEffect(() => { - if (isOpen()) { - 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); + const initialTags = createMemo(() => { + 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); } } - setInitialTags(tags); + } 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) => { diff --git a/src/components/QuickEntryForm.tsx b/src/components/QuickEntryForm.tsx index 90e93db..23eeed8 100644 --- a/src/components/QuickEntryForm.tsx +++ b/src/components/QuickEntryForm.tsx @@ -43,6 +43,26 @@ export const QuickEntryForm: Component = (props) => { } }); + // Reactive sync from props (handles context changes while open) + let lastInitialTags: string[] = []; + createEffect(() => { + const initial = props.initialTags || []; + + setTags(prev => { + // 1. Identify context tags that were removed + const removed = lastInitialTags.filter(t => !initial.includes(t)); + // 2. Filter them out of the current tag list + let next = prev.filter(t => !removed.includes(t)); + // 3. Add new context tags that aren't already present + initial.forEach(t => { + if (!next.includes(t)) next.push(t); + }); + return next; + }); + + lastInitialTags = [...initial]; + }); + // Reactive shorthand parsing createEffect(() => { const text = input();