diff --git a/src/views/NotepadView.tsx b/src/views/NotepadView.tsx index e84f08b..9b634bc 100644 --- a/src/views/NotepadView.tsx +++ b/src/views/NotepadView.tsx @@ -81,7 +81,7 @@ export const NotepadView: Component<{ }); createEffect(() => { - const note = activeNote(); + const note = taskLinkOwnerNote(); if (!note) return; const linkageSignature = `${note.id}|${note.key || note.title}|${(note.tasks || []).join(",")}|${note.updated}`; void linkageSignature; @@ -94,6 +94,22 @@ export const NotepadView: Component<{ return store.notes.find(n => n.id === id) || null; }); + const getImmediateParentNote = (note: Note | null): Note | null => { + if (!note) return null; + const parentTag = note.tags?.find(t => t.startsWith("child-of-")); + if (!parentTag) return null; + const parentId = parentTag.replace("child-of-", ""); + return store.notes.find(n => n.id === parentId) || null; + }; + + const taskLinkOwnerNote = createMemo(() => { + const note = activeNote(); + if (!note) return null; + return getImmediateParentNote(note) || note; + }); + + const isChildNote = createMemo(() => !!getImmediateParentNote(activeNote())); + const handleUpdateNote = async (id: string, data: Partial) => { await updateNote(id, data); }; @@ -141,7 +157,7 @@ export const NotepadView: Component<{ }; const handleLinkTask = async (taskId: string) => { - const note = activeNote(); + const note = taskLinkOwnerNote(); if (!note) return; const task = store.tasks.find(existing => existing.id === taskId); const noteTag = buildNoteTag(note.key || note.title); @@ -155,7 +171,8 @@ export const NotepadView: Component<{ }; const handleUnlinkTask = async (taskId: string) => { - const note = activeNote(); + if (isChildNote()) return; + const note = taskLinkOwnerNote(); if (!note) return; const task = store.tasks.find(existing => existing.id === taskId); const noteTag = buildNoteTag(note.key || note.title).toLowerCase(); @@ -168,7 +185,7 @@ export const NotepadView: Component<{ // Linked tasks calculation const linkedTasks = createMemo(() => { - const note = activeNote(); + const note = taskLinkOwnerNote(); if (!note) return []; const noteTagName = buildNoteTag(note.key || note.title).toLowerCase(); return store.tasks.filter(t => { @@ -181,7 +198,7 @@ export const NotepadView: Component<{ }); const unlinkedTasks = createMemo(() => { - const note = activeNote(); + const note = taskLinkOwnerNote(); if (!note) return []; const q = linkSearchQuery().toLowerCase(); @@ -271,6 +288,10 @@ export const NotepadView: Component<{ }; const openQuickEntry = () => { + const ownerNote = taskLinkOwnerNote(); + if (ownerNote) { + (window as any)._activeNoteId = ownerNote.id; + } window.dispatchEvent(new KeyboardEvent('keydown', { metaKey: true, key: 'k' })); }; @@ -390,9 +411,6 @@ export const NotepadView: Component<{ return s.startsWith('
{ - return (note()?.tags || []).some(t => t.startsWith("child-of-")); - }); return ( <> @@ -744,14 +762,14 @@ export const NotepadView: Component<{

No tasks linked yet.

-

Link an existing task, create a new one, or add the tag #{note().title} to a task.

+

Link an existing task, create a new one, or add the tag #{taskLinkOwnerNote()?.title || note().title} to a task.

}> {(task) => (
{/* If explicitly linked, allow unlinking. If linked by tag, they should remove the tag from the task, which we can't easily do here unless we implement it. */} - +