mirror of
https://github.com/Zakkaus/doona.git
synced 2026-12-06 16:01:00 +00:00
Move the ten bare keys (clear, close, hubs, lang, moreOptions, palette, refresh, search, theme, wordmark) under ui. or shell., and policy.sectionCount to ui.sectionCount since the node menu uses it outside the policy pages. check:i18n now rejects a key without an area. prefix.
71 lines
2.7 KiB
TypeScript
71 lines
2.7 KiB
TypeScript
import {useEffect, useState} from 'react';
|
|
import {useT} from '../i18n';
|
|
import {storageKeys} from '../api/storage';
|
|
import {Link, useScrollStrip, useSlider} from '../ui/ui';
|
|
import type {NavGroup} from './view';
|
|
|
|
const key = storageKeys.hubPages;
|
|
function readLast(): Record<string, string> {
|
|
try {
|
|
return JSON.parse(sessionStorage.getItem(key) ?? '{}') ?? {};
|
|
} catch {
|
|
return {};
|
|
}
|
|
}
|
|
|
|
// Below the side navigation's breakpoint, the hubs sit in a bottom bar after the Material 3 navigation bar: an icon
|
|
// and a label each, the open hub's icon on a pill. A hub opens on the page last seen in it this session. Moving between
|
|
// hubs or pages adds a history entry, as a web page does, so Back returns to the page seen before.
|
|
export function HubBar({groups}: {groups: NavGroup[]}) {
|
|
const t = useT();
|
|
const [last, setLast] = useState(readLast);
|
|
const open = groups.flatMap(group => group.items.filter(item => item.current).map(item => [group.id, item.path] as const))[0];
|
|
if (open && last[open[0]] !== open[1]) setLast({...last, [open[0]]: open[1]});
|
|
useEffect(() => {
|
|
try {
|
|
sessionStorage.setItem(key, JSON.stringify(last));
|
|
} catch {
|
|
/* Storage can be unavailable; the bar then remembers for this page load. */
|
|
}
|
|
}, [last]);
|
|
return (
|
|
<nav className="rp-hubbar" aria-label={t('shell.hubs')}>
|
|
{groups.map(group => {
|
|
const Icon = group.items[0].Icon;
|
|
return (
|
|
<Link
|
|
key={group.id}
|
|
href={(group.items.find(item => item.path === last[group.id]) ?? group.items[0]).href}
|
|
aria-current={open?.[0] === group.id ? 'page' : undefined}
|
|
>
|
|
<span className="rp-hubbar-pill">
|
|
<Icon />
|
|
</span>
|
|
{group.label}
|
|
</Link>
|
|
);
|
|
})}
|
|
</nav>
|
|
);
|
|
}
|
|
|
|
// The open hub's pages, above the content: links in the segmented control's look, since picking one navigates rather
|
|
// than sets a value, and the pages carry tabs of their own. Pages too wide for the phone scroll like a page's tabs, with
|
|
// the current one kept in view.
|
|
export function HubPages({hub, route}: {hub: NavGroup; route: string}) {
|
|
const [ref, pos] = useSlider(route, '[aria-current="page"]');
|
|
useScrollStrip(ref, route, '[aria-current="page"]');
|
|
return (
|
|
<nav className="rp-hubnav" aria-label={hub.label}>
|
|
<div ref={ref} className="rp-seg">
|
|
{pos && <span className="rp-slider" data-still={pos.still || undefined} style={{left: pos.x, width: pos.w}} />}
|
|
{hub.items.map(item => (
|
|
<Link key={item.id} appearance="button" href={item.href} aria-current={item.current ? 'page' : undefined}>
|
|
{item.label}
|
|
</Link>
|
|
))}
|
|
</div>
|
|
</nav>
|
|
);
|
|
}
|