From 7289a60db3a43b23bb0c2ca745f6c105ba8be96e Mon Sep 17 00:00:00 2001 From: Test Date: Fri, 6 Mar 2026 21:35:18 +0100 Subject: [PATCH] feat: add handleToggleTypeVisibility to useEntryActions Toggle visible property on Type note frontmatter: sets visible:false to hide, deletes visible property to show (defaults to visible). Wire up in App.tsx via onToggleTypeVisibility prop. Co-Authored-By: Claude Opus 4.6 --- src/App.tsx | 2 +- src/hooks/useEntryActions.test.ts | 38 +++++++++++++++++++++++++++++++ src/hooks/useEntryActions.ts | 14 +++++++++++- 3 files changed, 52 insertions(+), 2 deletions(-) diff --git a/src/App.tsx b/src/App.tsx index 992dd283..759af138 100644 --- a/src/App.tsx +++ b/src/App.tsx @@ -500,7 +500,7 @@ function App() { {sidebarVisible && ( <>
- +
diff --git a/src/hooks/useEntryActions.test.ts b/src/hooks/useEntryActions.test.ts index da4b863e..bf82b312 100644 --- a/src/hooks/useEntryActions.test.ts +++ b/src/hooks/useEntryActions.test.ts @@ -289,4 +289,42 @@ describe('useEntryActions', () => { expect(updateEntry).not.toHaveBeenCalled() }) }) + + describe('handleToggleTypeVisibility', () => { + it('sets visible to false when currently visible (null/default)', async () => { + const typeEntry = makeEntry({ isA: 'Type', title: 'Journal', path: '/vault/type/journal.md', visible: null }) + const { result } = setup([typeEntry]) + + await act(async () => { + await result.current.handleToggleTypeVisibility('Journal') + }) + + expect(handleUpdateFrontmatter).toHaveBeenCalledWith('/vault/type/journal.md', 'visible', false) + expect(updateEntry).toHaveBeenCalledWith('/vault/type/journal.md', { visible: false }) + }) + + it('sets visible to true (deletes property) when currently hidden', async () => { + const typeEntry = makeEntry({ isA: 'Type', title: 'Journal', path: '/vault/type/journal.md', visible: false }) + const { result } = setup([typeEntry]) + + await act(async () => { + await result.current.handleToggleTypeVisibility('Journal') + }) + + expect(handleDeleteProperty).toHaveBeenCalledWith('/vault/type/journal.md', 'visible') + expect(updateEntry).toHaveBeenCalledWith('/vault/type/journal.md', { visible: null }) + }) + + it('auto-creates type entry when not found', async () => { + const { result } = setup([]) + + await act(async () => { + await result.current.handleToggleTypeVisibility('Journal') + }) + + expect(createTypeEntry).toHaveBeenCalledWith('Journal') + expect(handleUpdateFrontmatter).toHaveBeenCalledWith('/vault/type/journal.md', 'visible', false) + expect(updateEntry).toHaveBeenCalledWith('/vault/type/journal.md', { visible: false }) + }) + }) }) diff --git a/src/hooks/useEntryActions.ts b/src/hooks/useEntryActions.ts index b91572d4..0d8efa20 100644 --- a/src/hooks/useEntryActions.ts +++ b/src/hooks/useEntryActions.ts @@ -80,5 +80,17 @@ export function useEntryActions({ } }, [entries, handleUpdateFrontmatter, handleDeleteProperty, updateEntry]) - return { handleTrashNote, handleRestoreNote, handleArchiveNote, handleUnarchiveNote, handleCustomizeType, handleReorderSections, handleUpdateTypeTemplate, handleRenameSection } + const handleToggleTypeVisibility = useCallback(async (typeName: string) => { + let typeEntry = findTypeEntry(entries, typeName) + if (!typeEntry) typeEntry = await createTypeEntry(typeName) + if (typeEntry.visible === false) { + updateEntry(typeEntry.path, { visible: null }) + await handleDeleteProperty(typeEntry.path, 'visible') + } else { + updateEntry(typeEntry.path, { visible: false }) + await handleUpdateFrontmatter(typeEntry.path, 'visible', false) + } + }, [entries, handleUpdateFrontmatter, handleDeleteProperty, updateEntry, createTypeEntry]) + + return { handleTrashNote, handleRestoreNote, handleArchiveNote, handleUnarchiveNote, handleCustomizeType, handleReorderSections, handleUpdateTypeTemplate, handleRenameSection, handleToggleTypeVisibility } }