refactor(web): extract app shell and routing

Refs #247

Co-Authored-By: OpenAI Codex <codex@openai.com>
This commit is contained in:
2026-07-15 22:34:19 +02:00
co-authored by OpenAI Codex
parent 0416c00f96
commit ce5aaa8706
4 changed files with 1148 additions and 1150 deletions
+35 -1150
View File
File diff suppressed because it is too large Load Diff
+364
View File
@@ -0,0 +1,364 @@
import {
Fragment,
useEffect,
useRef,
useState,
type KeyboardEvent,
type MouseEvent,
type ReactNode
} from 'react';
import {
Bell,
CalendarClock,
Cast,
Check,
ChevronDown,
CircleHelp,
ClipboardCopy,
Info,
ListVideo,
Plus,
Search
} from 'lucide-react';
import chicoryMarkUrl from '../../../design-system/assets/chicory-mark.svg';
import {
useChannelsQuery,
useDashboardVersionQuery,
type DashboardHealthQueryState
} from '../api';
import {
Button,
IconButton,
NavItem,
NavSection
} from '../components';
import {
designSystemThemes,
type DesignSystemThemeId
} from '../designSystem';
import { usePrimaryActionHandler } from '../primaryAction';
import { navigateToPath } from '../routing';
import { DashboardHealthSummary } from '../screens/DashboardScreen';
import { UnauthorizedBanner } from '../UnauthorizedBanner';
import { UserMenu } from '../UserMenu';
import {
routeById,
routeHref,
sidebarNavGroups,
type ScreenId,
type ScreenRoute
} from './routes';
type NavigateHandler = (route: ScreenRoute, event: MouseEvent) => void;
function SidebarNavGroup({
activeRoute,
ids,
onNavigate
}: {
activeRoute: ScreenRoute | null;
ids: readonly ScreenId[];
onNavigate: NavigateHandler;
}) {
return (
<>
{ids.map((id) => {
const route = routeById.get(id)!;
return (
<NavItem
key={route.id}
icon={route.icon}
label={route.label}
active={route.id === activeRoute?.id}
badge={route.badge}
badgeTone="warn"
href={routeHref(route)}
onClick={(event) => onNavigate(route, event)}
/>
);
})}
</>
);
}
function ThemeSwitcher({
theme,
onThemeChange
}: {
theme: DesignSystemThemeId;
onThemeChange: (theme: DesignSystemThemeId) => void;
}) {
return (
<section className="ctv-theme-switcher" aria-label="Theme">
<span>Theme</span>
<div>
{designSystemThemes.map(({ id, description, label }) => (
<button
key={id}
type="button"
className={`ctv-theme-swatch ctv-theme-swatch-${id}`}
aria-label={description}
aria-pressed={theme === id}
title={label}
onClick={() => onThemeChange(id)}
/>
))}
</div>
</section>
);
}
function Sidebar({
activeRoute,
healthState,
onNavigate
}: {
activeRoute: ScreenRoute | null;
healthState: DashboardHealthQueryState;
onNavigate: NavigateHandler;
}) {
return (
<aside className="ctv-sidebar">
<div className="ctv-brand">
<img src={chicoryMarkUrl} alt="ChicoryTV" />
<span className="ctv-brand-wordmark">
Chicory<span>TV</span>
</span>
</div>
<nav aria-label="Primary" className="ctv-nav">
{sidebarNavGroups.map(({ ids, label }) => (
<Fragment key={label ?? 'Primary'}>
{label ? <NavSection>{label}</NavSection> : null}
<SidebarNavGroup activeRoute={activeRoute} ids={ids} onNavigate={onNavigate} />
</Fragment>
))}
</nav>
<div className="ctv-sidebar-health">
<div>
<span>ChicoryTV</span>
<SidebarVersion />
</div>
<DashboardHealthSummary healthState={healthState} />
</div>
</aside>
);
}
function SidebarVersion() {
const versionQuery = useDashboardVersionQuery();
if (versionQuery.status === 'success') {
return <code>{versionQuery.version.appVersion ?? 'version unknown'}</code>;
}
if (versionQuery.status === 'error') {
return <code>version unavailable</code>;
}
return <code>loading version</code>;
}
function EndpointRow({ icon, label, url }: { icon: ReactNode; label: string; url: string }) {
const [copied, setCopied] = useState(false);
const copyUrl = () => {
void navigator.clipboard?.writeText(url);
setCopied(true);
window.setTimeout(() => setCopied(false), 1200);
};
return (
<div className="ctv-connect-endpoint">
<span className="ctv-connect-endpoint-icon">{icon}</span>
<div>
<strong>{label}</strong>
<code>{url}</code>
</div>
<button type="button" onClick={copyUrl}>
{copied ? <Check aria-hidden="true" size={13} /> : <ClipboardCopy aria-hidden="true" size={13} />}
{copied ? 'Copied' : 'Copy'}
</button>
</div>
);
}
function ConnectMenu() {
const [open, setOpen] = useState(false);
const menuRef = useRef<HTMLDivElement>(null);
const channelsQuery = useChannelsQuery();
const playlistUrl = `${window.location.origin}/iptv/channels.m3u`;
const guideUrl = `${window.location.origin}/iptv/xmltv.xml`;
useEffect(() => {
if (open) {
menuRef.current?.focus();
}
}, [open]);
const onMenuKeyDown = (event: KeyboardEvent<HTMLDivElement>) => {
if (event.key === 'Escape') {
setOpen(false);
}
};
const channelCountLabel = (() => {
if (channelsQuery.status === 'loading') {
return 'Loading channels';
}
if (channelsQuery.status === 'error') {
return 'Channels unavailable';
}
const count = channelsQuery.channels.length;
return `${count} ${count === 1 ? 'channel' : 'channels'}`;
})();
return (
<div className="ctv-connect">
<button
type="button"
className="ctv-connect-button"
aria-expanded={open}
onClick={() => setOpen((current) => !current)}
>
<Cast aria-hidden="true" size={15} />
Connect
<ChevronDown aria-hidden="true" size={13} />
</button>
{open && (
<>
<button
type="button"
className="ctv-connect-dismiss"
aria-label="Close Connect menu"
onClick={() => setOpen(false)}
/>
<div
className="ctv-connect-menu"
role="dialog"
aria-label="Connect a player"
tabIndex={-1}
ref={menuRef}
onKeyDown={onMenuKeyDown}
>
<div className="ctv-connect-header">
<strong>Connect a player</strong>
<span>{channelCountLabel}</span>
</div>
<EndpointRow
icon={<ListVideo aria-hidden="true" size={15} />}
label="M3U playlist"
url={playlistUrl}
/>
<EndpointRow
icon={<CalendarClock aria-hidden="true" size={15} />}
label="XMLTV guide"
url={guideUrl}
/>
<p>
<Info aria-hidden="true" size={13} />
Works with any IPTV player.
</p>
</div>
</>
)}
</div>
);
}
function TopBar({ route }: { route: ScreenRoute | null }) {
const title = route?.title ?? 'Page not found';
const kicker = route?.kicker ?? 'Unknown route';
const primaryAction = route?.primaryAction ?? '';
const primaryActionHandler = usePrimaryActionHandler(route?.id ?? '');
const [searchValue, setSearchValue] = useState('');
return (
<header className="ctv-topbar">
<div className="ctv-topbar-title">
<p>{kicker}</p>
<h1>{title}</h1>
</div>
<form
className="ctv-topbar-search"
onSubmit={(event) => {
event.preventDefault();
const trimmed = searchValue.trim();
if (trimmed) {
navigateToPath(`/app/search?query=${encodeURIComponent(trimmed)}`);
}
}}
role="search"
>
<Search aria-hidden="true" size={15} />
<input
aria-label="Search"
onChange={(event) => setSearchValue(event.target.value)}
placeholder="Search movies, shows, music..."
type="search"
value={searchValue}
/>
</form>
<div className="ctv-topbar-spacer" />
<div className="ctv-topbar-tools">
<UserMenu />
<ConnectMenu />
<span className="ctv-topbar-divider" />
<IconButton title="Documentation" size="sm">
<CircleHelp aria-hidden="true" size={17} />
</IconButton>
<IconButton title="Notifications" size="sm">
<Bell aria-hidden="true" size={17} />
</IconButton>
<span className="ctv-avatar">TB</span>
</div>
{route && primaryAction && primaryActionHandler ? (
<Button
startIcon={<Plus aria-hidden="true" size={15} />}
onClick={primaryActionHandler}
>
{primaryAction}
</Button>
) : null}
</header>
);
}
export function AppShell({
children,
healthState,
onNavigate,
onThemeChange,
route,
theme
}: {
children: ReactNode;
healthState: DashboardHealthQueryState;
onNavigate: NavigateHandler;
onThemeChange: (theme: DesignSystemThemeId) => void;
route: ScreenRoute | null;
theme: DesignSystemThemeId;
}) {
return (
<div className="ctv-app-shell">
<Sidebar activeRoute={route} healthState={healthState} onNavigate={onNavigate} />
<div className="ctv-shell-body">
<TopBar route={route} />
<UnauthorizedBanner />
<main className="ctv-main">
<ThemeSwitcher theme={theme} onThemeChange={onThemeChange} />
{children}
</main>
</div>
</div>
);
}
+225
View File
@@ -0,0 +1,225 @@
import { useEffect, useState } from 'react';
import { Info } from 'lucide-react';
import type { DashboardHealthQueryState } from '../api';
import { ChannelBuilderScreen } from '../builder/ChannelBuilder';
import { Card } from '../components';
import {
parseLibrariesSubRoute,
parseMediaSubRoute
} from '../routing';
import { ApiKeyScreen } from '../screens/ApiKeyScreen';
import { BlockPlayoutTroubleshootingScreen } from '../screens/BlockPlayoutTroubleshootingScreen';
import { BlocksScreen } from '../screens/BlocksScreen';
import { ChannelEditScreen } from '../screens/ChannelEditScreen';
import { ChannelsScreen } from '../screens/ChannelsScreen';
import { CollectionsScreen } from '../screens/CollectionsScreen';
import { DashboardScreen } from '../screens/DashboardScreen';
import { DecoTemplatesScreen } from '../screens/DecoTemplatesScreen';
import { DecosScreen } from '../screens/DecosScreen';
import { FFmpegProfilesScreen } from '../screens/FFmpegProfilesScreen';
import { FillerPresetsScreen } from '../screens/FillerPresetsScreen';
import { GuideScreen } from '../screens/GuideScreen';
import { ImageBrowserScreen } from '../screens/ImageBrowserScreen';
import { LibrariesScreen } from '../screens/LibrariesScreen';
import { LocalLibraryEditScreen } from '../screens/LocalLibraryEditScreen';
import { LogsScreen } from '../screens/LogsScreen';
import { MediaBrowseScreen } from '../screens/MediaBrowseScreen';
import {
ArtistDetailScreen,
MovieDetailScreen,
SeasonDetailScreen,
ShowDetailScreen
} from '../screens/MediaDetailScreen';
import { MultiCollectionsScreen } from '../screens/MultiCollectionsScreen';
import { PathReplacementsEditScreen } from '../screens/PathReplacementsEditScreen';
import { PlaybackTroubleshootingScreen } from '../screens/PlaybackTroubleshootingScreen';
import { PlexSourceScreen } from '../screens/PlexSourceScreen';
import { PlaylistsScreen } from '../screens/PlaylistsScreen';
import { PlayoutsRouteScreen } from '../screens/PlayoutsScreen';
import { RemoteConnectionEditScreen } from '../screens/RemoteConnectionEditScreen';
import { RemoteLibrariesEditScreen } from '../screens/RemoteLibrariesEditScreen';
import { RemoteSourceScreen } from '../screens/RemoteSourceScreen';
import { RerunCollectionsScreen } from '../screens/RerunCollectionsScreen';
import { SchedulesScreen } from '../screens/SchedulesScreen';
import { SearchScreen } from '../screens/SearchScreen';
import { SettingsScreen } from '../screens/SettingsScreen';
import { TemplatesScreen } from '../screens/TemplatesScreen';
import { TraktListsScreen } from '../screens/TraktListsScreen';
import { TrashScreen } from '../screens/TrashScreen';
import { TroubleshootingScreen } from '../screens/TroubleshootingScreen';
import { WatermarksScreen } from '../screens/WatermarksScreen';
import { YamlValidatorScreen } from '../screens/YamlValidatorScreen';
import {
normalizeAppPath,
type ScreenId,
type ScreenRoute
} from './routes';
function NotFoundScreen() {
const pathname = normalizeAppPath(window.location.pathname);
return (
<div className="ctv-screen-stack">
<Card title={<h2>Unknown app route</h2>} subtitle="This URL does not match a ChicoryTV screen.">
<div className="ctv-placeholder-layout">
<div className="ctv-placeholder-icon"><Info aria-hidden="true" size={20} /></div>
<div>
<h3>Requested path</h3>
<p>{pathname}</p>
</div>
</div>
</Card>
</div>
);
}
// The Media nav entry owns detail sub-pages (/app/media/{movies|shows|seasons|artists}/{id}) and the
// image folder browser (/app/media/images/browser). Like PlayoutsRouteScreen, this wrapper tracks
// pathname locally + listens for popstate, because routeFromLocation() returns the SAME 'media'
// ScreenRoute object for the base grid and every sub-path (Object.is bails App's setActiveRoute).
export function MediaRouteScreen() {
const [pathname, setPathname] = useState(() => window.location.pathname);
const [search, setSearch] = useState(() => window.location.search);
useEffect(() => {
const onPopState = () => {
setPathname(window.location.pathname);
setSearch(window.location.search);
};
window.addEventListener('popstate', onPopState);
return () => window.removeEventListener('popstate', onPopState);
}, []);
const sub = parseMediaSubRoute(pathname);
if (sub?.kind === 'movie') {
return <MovieDetailScreen key={pathname} id={sub.id} />;
}
if (sub?.kind === 'show') {
return <ShowDetailScreen key={pathname} id={sub.id} />;
}
if (sub?.kind === 'season') {
return <SeasonDetailScreen key={pathname} id={sub.id} />;
}
if (sub?.kind === 'artist') {
return <ArtistDetailScreen key={pathname} id={sub.id} />;
}
if (sub?.kind === 'images') {
return <ImageBrowserScreen key={pathname} />;
}
return <MediaBrowseScreen key={search} />;
}
// The Libraries nav entry owns the media-source editor sub-paths. CRITICAL (design §D.2, finding 4):
// unlike PlayoutsRouteScreen/MediaRouteScreen this wrapper does NOT register its own `popstate`
// listener. Its editor sub-screens register a dirty guard, so App must approve the path first and
// pass it down. This wrapper never reads a raw navigation event.
export function LibrariesRouteScreen({ subPath }: { subPath: string }) {
const sub = parseLibrariesSubRoute(subPath);
if (sub === null) {
return <LibrariesScreen />;
}
switch (sub.kind) {
case 'local-new':
case 'local-edit':
return <LocalLibraryEditScreen key={subPath} />;
case 'remote-source':
return sub.family === 'plex'
? <PlexSourceScreen key={subPath} />
: <RemoteSourceScreen key={subPath} family={sub.family} />;
case 'remote-connection':
return <RemoteConnectionEditScreen key={subPath} family={sub.family} />;
case 'remote-libraries':
return <RemoteLibrariesEditScreen key={subPath} family={sub.family} sourceId={sub.id} />;
case 'remote-path-replacements':
return <PathReplacementsEditScreen key={subPath} family={sub.family} sourceId={sub.id} />;
}
}
function assertNeverScreen(screenId: never): never {
throw new Error(`Unhandled screen route: ${String(screenId)}`);
}
export function ScreenContent({
healthState,
librariesSubPath,
route
}: {
healthState: DashboardHealthQueryState;
librariesSubPath: string;
route: ScreenRoute | null;
}) {
if (route === null) {
return <NotFoundScreen />;
}
const routeId: ScreenId = route.id;
switch (routeId) {
case 'dashboard':
return <DashboardScreen healthState={healthState} />;
case 'channels':
return <ChannelsScreen />;
case 'builder':
return <ChannelBuilderScreen />;
case 'editChannel':
return <ChannelEditScreen key={window.location.pathname} />;
case 'guide':
return <GuideScreen />;
case 'schedules':
return <SchedulesScreen />;
case 'blocks':
return <BlocksScreen key={window.location.pathname} />;
case 'templates':
return <TemplatesScreen key={window.location.pathname} />;
case 'decos':
return <DecosScreen key={window.location.pathname} />;
case 'decoTemplates':
return <DecoTemplatesScreen key={window.location.pathname} />;
case 'playouts':
return <PlayoutsRouteScreen />;
case 'libraries':
return <LibrariesRouteScreen subPath={librariesSubPath} />;
case 'settings':
return <SettingsScreen />;
case 'apiKey':
return <ApiKeyScreen />;
case 'media':
return <MediaRouteScreen />;
case 'search':
return <SearchScreen key={window.location.search} />;
case 'trash':
return <TrashScreen />;
case 'collections':
return <CollectionsScreen />;
case 'multiCollections':
return <MultiCollectionsScreen />;
case 'rerunCollections':
return <RerunCollectionsScreen />;
case 'playlists':
return <PlaylistsScreen />;
case 'traktLists':
return <TraktListsScreen key={window.location.pathname} />;
case 'fillerPresets':
return <FillerPresetsScreen />;
case 'ffmpegProfiles':
return <FFmpegProfilesScreen />;
case 'watermarks':
return <WatermarksScreen />;
case 'logs':
return <LogsScreen />;
case 'troubleshooting':
return <TroubleshootingScreen />;
case 'blockPlayoutTroubleshooting':
return <BlockPlayoutTroubleshootingScreen />;
case 'playbackTroubleshooting':
return <PlaybackTroubleshootingScreen key={window.location.search} />;
case 'yamlValidator':
return <YamlValidatorScreen />;
default:
return assertNeverScreen(routeId);
}
}
+524
View File
@@ -0,0 +1,524 @@
import type { ReactNode } from 'react';
import {
Boxes,
Palette,
CalendarClock,
CalendarDays,
CalendarRange,
Clapperboard,
Film,
FolderTree,
KeyRound,
Layers,
LayoutDashboard,
LayoutGrid,
Library,
Link2,
ListChecks,
ListMusic,
ListVideo,
Plus,
Repeat,
ScrollText,
Search,
Settings,
SlidersHorizontal,
Stamp,
Stethoscope,
Trash2,
Tv
} from 'lucide-react';
export type ScreenId =
| 'dashboard'
| 'channels'
| 'builder'
| 'editChannel'
| 'guide'
| 'schedules'
| 'blocks'
| 'templates'
| 'decos'
| 'decoTemplates'
| 'playouts'
| 'media'
| 'search'
| 'trash'
| 'collections'
| 'multiCollections'
| 'rerunCollections'
| 'playlists'
| 'fillerPresets'
| 'libraries'
| 'traktLists'
| 'ffmpegProfiles'
| 'watermarks'
| 'settings'
| 'apiKey'
| 'logs'
| 'troubleshooting'
| 'blockPlayoutTroubleshooting'
| 'playbackTroubleshooting'
| 'yamlValidator';
export interface ScreenRoute {
id: ScreenId;
path: string;
label: string;
title: string;
kicker: string;
description: string;
icon: ReactNode;
primaryAction: string;
placeholder: string;
badge?: number;
// Screens that own linkable sub-sections (e.g. /app/settings/streaming) opt in here;
// the sub-path is otherwise unowned and 404s (see routeFromLocation).
allowSubPaths?: boolean;
}
// This is the one stable route-object table for the application. routeFromLocation returns
// references from this array so allowSubPaths navigations intentionally preserve object identity.
export const routes: ScreenRoute[] = [
{
id: 'dashboard',
path: '/app',
label: 'Dashboard',
title: 'Dashboard',
kicker: 'Overview',
description: 'On-air status, health checks, and recent server activity.',
icon: <LayoutDashboard aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Dashboard workspace'
},
{
id: 'channels',
path: '/app/channels',
label: 'Channels',
title: 'Channels',
kicker: 'Lineup',
description: 'Dense channel table, ordering tools, bulk actions, and playback status.',
icon: <Tv aria-hidden="true" size={16} />,
primaryAction: 'Add Channel',
placeholder: 'Channel list workspace'
},
{
id: 'builder',
path: '/app/new-channel',
label: 'New Channel',
title: 'New Channel',
kicker: 'Builder',
description: 'Library-to-lineup channel creation flow with template-backed defaults.',
icon: <Plus aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Channel builder workspace'
},
{
// Not in the sidebar nav; reached via the edit pencil on the channel table. The
// screen owns parsing the {id} suffix (see ChannelEditScreen), so it opts into
// sub-paths like /app/edit-channel/5.
id: 'editChannel',
path: '/app/edit-channel',
label: 'Edit Channel',
title: 'Edit Channel',
kicker: 'Channel',
description: 'Full channel editor: identity, playout, streaming, selection and branding.',
icon: <Tv aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Channel editor workspace',
allowSubPaths: true
},
{
id: 'guide',
path: '/app/guide',
label: 'Guide',
title: 'Guide',
kicker: 'EPG',
description: 'Timeline grid with channel rows, programme blocks, and a live now marker.',
icon: <LayoutGrid aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'EPG grid workspace'
},
{
id: 'schedules',
path: '/app/schedules',
label: 'Schedules',
title: 'Schedules',
kicker: 'Programming',
description: 'Two-pane schedule editor with drag ordering and progressive details.',
icon: <CalendarClock aria-hidden="true" size={16} />,
primaryAction: 'Add Schedule',
placeholder: 'Schedule editor workspace'
},
{
// The editor lives at a sub-path (/app/blocks/{id}); BlocksScreen owns parsing the id suffix.
id: 'blocks',
path: '/app/blocks',
label: 'Blocks',
title: 'Blocks',
kicker: 'Programming',
description: 'Group blocks and edit their items, durations, and playout preview.',
icon: <Boxes aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Blocks workspace',
allowSubPaths: true
},
{
// The editor lives at a sub-path (/app/templates/{id}); TemplatesScreen owns parsing the id suffix.
id: 'templates',
path: '/app/templates',
label: 'Templates',
title: 'Templates',
kicker: 'Programming',
description: 'Group templates and assign blocks to times of day.',
icon: <CalendarDays aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Templates workspace',
allowSubPaths: true
},
{
// The editor lives at a sub-path (/app/decos/{id}); DecosScreen owns parsing the id suffix.
id: 'decos',
path: '/app/decos',
label: 'Decos',
title: 'Decos',
kicker: 'Programming',
description: 'Group decos and configure watermark, graphics, break content, and filler overrides.',
icon: <Palette aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Decos workspace',
allowSubPaths: true
},
{
// The editor lives at a sub-path (/app/deco-templates/{id}); DecoTemplatesScreen owns parsing the id suffix.
id: 'decoTemplates',
path: '/app/deco-templates',
label: 'Deco Templates',
title: 'Deco Templates',
kicker: 'Programming',
description: 'Group deco templates and assign decos to times of day.',
icon: <CalendarRange aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Deco templates workspace',
allowSubPaths: true
},
{
// The alternate-schedules / templates editors live at sub-paths
// (/app/playouts/{id}/alternate-schedules, /app/playouts/{id}/templates).
id: 'playouts',
path: '/app/playouts',
label: 'Playouts',
title: 'Playouts',
kicker: 'Runtime',
description: 'Playout state, reset controls, timeline diagnostics, and build warnings.',
icon: <ListVideo aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Playouts workspace',
allowSubPaths: true
},
{
id: 'media',
path: '/app/media',
label: 'Browse',
title: 'Browse Media',
kicker: 'Media',
description: 'Browse indexed movies, shows, episodes, music and more by kind.',
icon: <Clapperboard aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Media browse workspace',
allowSubPaths: true
},
{
id: 'search',
path: '/app/search',
label: 'Search',
title: 'Search',
kicker: 'Media',
description: 'Search across every media kind at once.',
icon: <Search aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Search workspace',
allowSubPaths: true
},
{
id: 'trash',
path: '/app/trash',
label: 'Trash',
title: 'Trash',
kicker: 'Media',
description: 'Library items whose files have gone missing.',
icon: <Trash2 aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Trash workspace'
},
{
id: 'collections',
path: '/app/collections',
label: 'Collections',
title: 'Collections',
kicker: 'Media',
description: 'Manual, smart, multi, playlist, search, and rerun collection management.',
icon: <FolderTree aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Collections workspace'
},
{
id: 'multiCollections',
path: '/app/multi-collections',
label: 'Multi-Collections',
title: 'Multi-Collections',
kicker: 'Media',
description: 'Group manual and smart collections into a single schedulable collection.',
icon: <Layers aria-hidden="true" size={16} />,
primaryAction: 'Add Multi-Collection',
placeholder: 'Multi-collections workspace'
},
{
id: 'rerunCollections',
path: '/app/rerun-collections',
label: 'Rerun Collections',
title: 'Rerun Collections',
kicker: 'Media',
description: 'A collection with distinct first-run and rerun playback orders.',
icon: <Repeat aria-hidden="true" size={16} />,
primaryAction: 'Add Rerun Collection',
placeholder: 'Rerun collections workspace'
},
{
id: 'playlists',
path: '/app/playlists',
label: 'Playlists',
title: 'Playlists',
kicker: 'Media',
description: 'Group, order, and preview playlist items scheduled into channels.',
icon: <ListMusic aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Playlists workspace'
},
{
id: 'fillerPresets',
path: '/app/filler-presets',
label: 'Filler Presets',
title: 'Filler Presets',
kicker: 'Media',
description: 'Pre/mid/post-roll, tail and fallback filler presets used by schedules.',
icon: <Film aria-hidden="true" size={16} />,
primaryAction: 'Add Filler Preset',
placeholder: 'Filler presets workspace',
allowSubPaths: true
},
{
// The media-source editors live at sub-paths (/app/libraries/local/{id}, /app/libraries/plex,
// /app/libraries/{jellyfin|emby}/connection, .../{id}/sync, .../{id}/path-replacements).
// Unlike other allowSubPaths screens, the libraries wrapper does NOT self-listen for popstate:
// its editors register a dirty guard, so App owns pathname/popstate and passes the approved
// sub-path down (see LibrariesRouteScreen + spa-conventions §8, design §D.2).
id: 'libraries',
path: '/app/libraries',
label: 'Libraries',
title: 'Libraries',
kicker: 'Sources',
description: 'Local, Plex, Jellyfin, and Emby media source monitoring.',
icon: <Library aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Libraries workspace',
allowSubPaths: true
},
{
// The editor lives at a sub-path (/app/trakt-lists/{id}); the screen owns parsing the
// {id} suffix itself (see TraktListsScreen), same pattern as editChannel/settings.
id: 'traktLists',
path: '/app/trakt-lists',
label: 'Trakt Lists',
title: 'Trakt Lists',
kicker: 'Media',
description: 'Add, match, and manage Trakt list imports.',
icon: <Link2 aria-hidden="true" size={16} />,
primaryAction: 'Add Trakt List',
placeholder: 'Trakt lists workspace',
allowSubPaths: true
},
{
id: 'ffmpegProfiles',
path: '/app/ffmpeg-profiles',
label: 'FFmpeg Profiles',
title: 'FFmpeg Profiles',
kicker: 'System',
description: 'Transcoding profiles: resolution, video/audio formats, hardware acceleration.',
icon: <SlidersHorizontal aria-hidden="true" size={16} />,
primaryAction: 'Add Profile',
placeholder: 'FFmpeg profiles workspace',
allowSubPaths: true
},
{
id: 'watermarks',
path: '/app/watermarks',
label: 'Watermarks',
title: 'Watermarks',
kicker: 'System',
description: 'Channel watermark overlays: image, position, size and opacity.',
icon: <Stamp aria-hidden="true" size={16} />,
primaryAction: 'Add Watermark',
placeholder: 'Watermarks workspace',
allowSubPaths: true
},
{
id: 'settings',
path: '/app/settings',
label: 'Settings',
title: 'Settings',
kicker: 'System',
description: 'Server configuration, access keys, FFmpeg profiles, and UI preferences.',
icon: <Settings aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Settings workspace',
allowSubPaths: true
},
{
// Since #295 the browser authenticates by session cookie; this screen only *displays* the
// server machine key (for MCP / external REST clients) and, for local accounts, changes the
// admin password — there is no key to "save" here (see spa-conventions §5e).
id: 'apiKey',
path: '/app/api-key',
label: 'API Key',
title: 'API Key',
kicker: 'System',
description: 'View the machine key for MCP and external REST clients, and change the local admin password.',
icon: <KeyRound aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'API key workspace'
},
{
id: 'logs',
path: '/app/logs',
label: 'Logs',
title: 'Logs',
kicker: 'System',
description: 'Recent server log entries with level and free-text filtering.',
icon: <ScrollText aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Logs workspace'
},
{
id: 'troubleshooting',
path: '/app/troubleshooting',
label: 'Troubleshooting',
title: 'Troubleshooting',
kicker: 'System',
description: 'Version, environment, hardware and FFmpeg capability diagnostics.',
icon: <Stethoscope aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Troubleshooting workspace'
},
{
id: 'blockPlayoutTroubleshooting',
path: '/app/troubleshooting/blocks',
label: 'Block History',
title: 'Block Playout Troubleshooting',
kicker: 'System',
description: 'Inspect a block playout, its blocks, and each block’s scheduling history.',
icon: <Boxes aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Block playout troubleshooting workspace'
},
{
id: 'playbackTroubleshooting',
path: '/app/troubleshooting/playback',
label: 'Playback Troubleshooting',
title: 'Playback Troubleshooting',
kicker: 'System',
description: 'Preview channel or media-item playback with a chosen FFmpeg profile and inspect the transcode logs.',
icon: <Stethoscope aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Playback troubleshooting workspace'
},
{
id: 'yamlValidator',
path: '/app/troubleshooting/yaml',
label: 'Schedule Validator',
title: 'Sequential Schedule Validator',
kicker: 'System',
description: 'Validate a sequential-schedule YAML document against the schema.',
icon: <ListChecks aria-hidden="true" size={16} />,
primaryAction: '',
placeholder: 'Sequential schedule validator workspace'
}
];
export const routeById = new Map(routes.map((route) => [route.id, route]));
export interface SidebarNavGroupDefinition {
label?: string;
ids: readonly ScreenId[];
}
export const sidebarNavGroups: SidebarNavGroupDefinition[] = [
{
ids: [
'dashboard',
'channels',
'builder',
'guide',
'schedules',
'blocks',
'templates',
'decos',
'decoTemplates',
'playouts'
]
},
{
label: 'Media',
ids: [
'media',
'search',
'trash',
'collections',
'multiCollections',
'rerunCollections',
'playlists',
'fillerPresets',
'libraries',
'traktLists'
]
},
{
label: 'System',
ids: [
'settings',
'apiKey',
'logs',
'troubleshooting',
'blockPlayoutTroubleshooting',
'yamlValidator',
'ffmpegProfiles',
'watermarks'
]
}
];
export function normalizeAppPath(pathname: string): string {
return pathname.replace(/\/+$/, '') || '/app';
}
export function routeFromLocation(): ScreenRoute | null {
const pathname = normalizeAppPath(window.location.pathname);
const exactMatch = routes.find((route) => route.path === pathname);
if (exactMatch) {
return exactMatch;
}
// Fall back to a sub-path of a route that has explicitly opted into linkable
// sub-sections (e.g. /app/settings/streaming) - the screen owns parsing the
// suffix itself (see SettingsScreen).
const prefixMatches = routes
.filter((route) => route.allowSubPaths && pathname.startsWith(`${route.path}/`))
.sort((a, b) => b.path.length - a.path.length);
return prefixMatches[0] ?? null;
}
export function routeHref(route: ScreenRoute): string {
return route.id === 'dashboard' ? '/app' : route.path;
}