From b1ba14f98e201ff35006bcab86e3e143eded7516 Mon Sep 17 00:00:00 2001 From: mesalogo Date: Wed, 9 Sep 2026 01:26:10 +0800 Subject: [PATCH] fix: move todo source entry to detail pane --- src/renderer/src/MagicNotesWorkspace.test.tsx | 4 + src/renderer/src/MagicNotesWorkspace.tsx | 133 +++++------------- .../src/i18n/locales/en-US/magicNotes.ts | 2 - .../src/i18n/locales/zh-CN/magicNotes.ts | 2 - src/renderer/src/styles.css | 20 +-- 5 files changed, 39 insertions(+), 122 deletions(-) diff --git a/src/renderer/src/MagicNotesWorkspace.test.tsx b/src/renderer/src/MagicNotesWorkspace.test.tsx index 47a9d60c..b4085e15 100644 --- a/src/renderer/src/MagicNotesWorkspace.test.tsx +++ b/src/renderer/src/MagicNotesWorkspace.test.tsx @@ -466,6 +466,10 @@ describe('MagicNotesWorkspace', () => { const sourceEntry = screen.getByRole('region', { name: '对应的笔记记录' }) + const todoDetail = screen.getByRole('region', { name: '待办详情' }) + const aiComments = screen.getByRole('complementary', { name: 'AI 评论' }) + expect(todoDetail).toContainElement(sourceEntry) + expect(aiComments).not.toContainElement(sourceEntry) expect(within(sourceEntry).getByText('发布笔记')).toBeInTheDocument() expect(within(sourceEntry).getByText('记录正文')).toBeInTheDocument() }) diff --git a/src/renderer/src/MagicNotesWorkspace.tsx b/src/renderer/src/MagicNotesWorkspace.tsx index fef9b90e..0460dc9f 100644 --- a/src/renderer/src/MagicNotesWorkspace.tsx +++ b/src/renderer/src/MagicNotesWorkspace.tsx @@ -485,10 +485,6 @@ export function MagicNotesWorkspace({ const [detail, setDetail] = useState() const [todoSourceDetail, setTodoSourceDetail] = useState() - const [todoSourceError, setTodoSourceError] = useState<{ - message: string - noteId: string - }>() const [loadStatus, setLoadStatus] = useState('loading') const [loadError, setLoadError] = useState('') const [refreshError, setRefreshError] = useState('') @@ -1408,30 +1404,6 @@ export function MagicNotesWorkspace({ const selectedTodoNoteId = selectedTodo?.noteId const selectedTodoEntryId = selectedTodo?.entryId - const loadTodoSource = useCallback( - async (noteId: string): Promise => { - const requestId = ++todoSourceRequestRef.current - try { - const sourceDetail = await window.goodbuddy.magicNotes.get(noteId) - if (todoSourceRequestRef.current === requestId) { - setTodoSourceDetail(sourceDetail) - setTodoSourceError(undefined) - } - } catch (sourceError) { - if (todoSourceRequestRef.current === requestId) { - setTodoSourceError({ - message: errorMessage( - sourceError, - tRef.current('errors.operationFailed') - ), - noteId - }) - } - } - }, - [] - ) - useEffect(() => { if (libraryView !== 'todos' || !selectedTodoNoteId) { return @@ -1442,41 +1414,27 @@ export function MagicNotesWorkspace({ .then((sourceDetail) => { if (todoSourceRequestRef.current === requestId) { setTodoSourceDetail(sourceDetail) - setTodoSourceError(undefined) } }) .catch((sourceError: unknown) => { if (todoSourceRequestRef.current === requestId) { - setTodoSourceError({ - message: errorMessage( - sourceError, - tRef.current('errors.operationFailed') - ), - noteId: selectedTodoNoteId - }) + notifyError(sourceError) } }) return () => { todoSourceRequestRef.current += 1 } - }, [libraryView, selectedTodoNoteId]) + }, [libraryView, notifyError, selectedTodoNoteId]) const selectedTodoSourceEntry = useMemo( () => - todoSourceDetail?.entries.find( - (entry) => entry.id === selectedTodoEntryId - ), - [selectedTodoEntryId, todoSourceDetail] + todoSourceDetail && todoSourceDetail.id === selectedTodoNoteId + ? todoSourceDetail.entries.find( + (entry) => entry.id === selectedTodoEntryId + ) + : undefined, + [selectedTodoEntryId, selectedTodoNoteId, todoSourceDetail] ) - const selectedTodoSourceError = - todoSourceError && todoSourceError.noteId === selectedTodoNoteId - ? todoSourceError.message - : '' - const todoSourceLoading = - Boolean(selectedTodoNoteId) && - todoSourceDetail?.id !== selectedTodoNoteId && - !selectedTodoSourceError - const reloadTodos = useCallback(async (): Promise => { const snapshot = await window.goodbuddy.magicNotes.listTodos() setTodos(snapshot.todos) @@ -1574,7 +1532,6 @@ export function MagicNotesWorkspace({ if (selectedTodoId === todo.id) { todoSourceRequestRef.current += 1 setTodoSourceDetail(result.note) - setTodoSourceError(undefined) } if (requestedNoteIdRef.current === result.note.id) { applyDetail(result.note) @@ -2767,6 +2724,31 @@ export function MagicNotesWorkspace({ {t('actions.openSourceNote')} +
+
+
+ {t('todos.sourceEntryHeading')} + {selectedTodo.noteTitle} +
+ {selectedTodoSourceEntry && ( + + )} +
+ {selectedTodoSourceEntry ? ( + + ) : ( +

+ {t('todos.sourceEntryMissing')} +

+ )} +
)} @@ -2838,55 +2820,6 @@ export function MagicNotesWorkspace({