Adds a "Customize sections" button above section groups in the sidebar. Clicking it opens a popover with per-type toggle switches. Hidden sections disappear from the sidebar entirely but notes remain accessible via All Notes and search. Visibility state is persisted in localStorage. - New useSectionVisibility hook: manages hidden sections set in localStorage - Sidebar: "Customize sections" button + popover with toggle UI - Outside-click closes the popover - allSectionGroups (built-in + custom) filtered by visibility before render Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
45 lines
1.1 KiB
TypeScript
45 lines
1.1 KiB
TypeScript
import { useState, useCallback } from 'react'
|
|
|
|
const STORAGE_KEY = 'laputa-hidden-sections'
|
|
|
|
function loadHiddenSections(): Set<string> {
|
|
try {
|
|
const raw = localStorage.getItem(STORAGE_KEY)
|
|
if (raw) {
|
|
const arr = JSON.parse(raw)
|
|
if (Array.isArray(arr)) return new Set(arr)
|
|
}
|
|
} catch {
|
|
// ignore corrupt data
|
|
}
|
|
return new Set()
|
|
}
|
|
|
|
function saveHiddenSections(hidden: Set<string>) {
|
|
localStorage.setItem(STORAGE_KEY, JSON.stringify([...hidden]))
|
|
}
|
|
|
|
export function useSectionVisibility() {
|
|
const [hiddenSections, setHiddenSections] = useState<Set<string>>(loadHiddenSections)
|
|
|
|
const toggleSection = useCallback((type: string) => {
|
|
setHiddenSections((prev) => {
|
|
const next = new Set(prev)
|
|
if (next.has(type)) {
|
|
next.delete(type)
|
|
} else {
|
|
next.add(type)
|
|
}
|
|
saveHiddenSections(next)
|
|
return next
|
|
})
|
|
}, [])
|
|
|
|
const isSectionVisible = useCallback(
|
|
(type: string) => !hiddenSections.has(type),
|
|
[hiddenSections],
|
|
)
|
|
|
|
return { hiddenSections, toggleSection, isSectionVisible }
|
|
}
|