import { useParams } from '@solidjs/router' import { Logger } from 'besonders-logger' import { createEffect, createMemo, Show } from 'solid-js' import { AppSettings } from '../components/settings/AppSettings' import { SharesSettings } from '../components/settings/SharesSettings' import { StorageSettings } from '../components/settings/StorageSettings' import { SubscriptionsSettings } from '../components/settings/SubscriptionsSettings' import { TagSettings } from '../components/settings/TagSettings' import { useGlobalInputHandlers } from '../data/keybindings' import { useLocationNavigate } from '../ui/utils-ui' const { WARN, LOG, DEBUG, VERBOSE, ERROR } = Logger.setup(Logger.INFO) // eslint-disable-line unused-imports/no-unused-vars export default () => { const params = useParams() const { locnav, location, navigate } = useLocationNavigate() DEBUG('!!! RENDER !!!', params) // trace(true) useGlobalInputHandlers() const active = createMemo(() => { const [section, ...sectionParams] = params.section?.split('/') const normalizedSection = section === 'publications' ? 'shares' : section const storedTab = localStorage.getItem('note3.settings.lastTab') const normalizedStoredTab = storedTab === 'publications' ? 'shares' : storedTab DEBUG(`Section?`, params.section, '->', { section: normalizedSection, sectionParams, localStorage: normalizedStoredTab }) return { section: normalizedSection || normalizedStoredTab, params: sectionParams, } }) const activeParams = createMemo(() => active().params) // ? possibly simpler const activeSection = createMemo(() => active().section || 'app') const setActive = (evt: CustomEvent) => { DEBUG(`Tab activated`, evt, active()) localStorage.setItem('note3.settings.lastTab', evt.detail.name) if (activeSection() !== evt.detail.name) { navigate(`/settings/${evt.detail.name}`, { replace: location.pathname === '/settings', }) } } createEffect(() => DEBUG(`active settings section:`, { ...active() })) let tabGroupRef // (i) we need both: the effect in case we have a section change while the component is mounted, and the active={} on the tab for the initial page load createEffect(() => tabGroupRef?.show(activeSection())) return (
App {/* Agent */} Storage Tags Shares Subscriptions { /* */ } {/* */} {/* */}
) }