Files
TREK/client/src/help/defineScreen.ts
T
Maurice 5584d287a9 refactor(help): register a screen from one description, and fix the doc links
Every context file carried its own copy of the same little guide factory and
the same context literal. Thirteen screens of a trip would have made thirteen
copies of it, which is both the duplication a quality gate counts and the
hand-mirrored state the repository asks us not to keep, so the shape moves into
defineScreen and a context file becomes data: ids, counts, docs, cross-links.

Four doc links never resolved. Trip-Planner and Sharing-and-Collaboration are
not wiki pages (Trip-Planner-Overview and Trip-Members-and-Sharing are), the
places import anchor is importing-multiple-places, and the offline anchor was
written in GitHub's slug, which is not the one the in-app reader produces.
Nothing caught them, so the registry test now checks every slug and every
anchor against wiki/, with the heading slug itself lifted out of HelpPage so
the reader and the test cannot drift apart.
2026-09-24 14:05:42 +02:00

75 lines
2.2 KiB
TypeScript

import type { HelpContext, HelpDocLink, HelpGuide, HelpGuideSize, HelpIcon } from './types'
/**
* One screen's whole registration, written once.
*
* Every `contexts/*.ts` file used to carry its own copy of the same little
* factory and the same context literal; the screens of a trip alone would have
* made thirteen copies of it. That repetition is what a duplication check
* counts, and it is exactly the hand-mirrored state the repository's rules ask
* us not to keep. So the shape lives here and a context file is data only: the
* ids, the counts, the docs and what relates to what.
*
* A guide is a row rather than an object because the rows are read as a table:
* one line per guide, the numbers under each other.
*/
export type GuideRow = [
id: string,
icon: HelpIcon,
size: HelpGuideSize,
steps: number,
tips: number,
docs: HelpDocLink | undefined,
related: string[],
/** Whether the guide carries a picture of the state after its last step. Default: no. */
result?: boolean,
]
export interface ScreenSpec {
id: string
icon: HelpIcon
/** How many "on this screen" bullets the catalogue has for it. */
bullets: number
/** Where the reference documentation continues. */
docs: HelpDocLink[]
/** The guides, in the order the panel lists them. */
guides: GuideRow[]
/** The screen this one lives under, for the switcher. */
parent?: string
/** Where the screen is in the app, for the "go there" button. */
route?: string
/** Whether `help-media/ctx/<id>.webp` exists. Default: yes. */
hero?: boolean
}
/** The context and the guides of one screen, from one description of it. */
export function defineScreen(spec: ScreenSpec): { context: HelpContext; guides: HelpGuide[] } {
const guides: HelpGuide[] = spec.guides.map(
([id, icon, size, steps, tips, docs, related, result = false]): HelpGuide => ({
id,
context: spec.id,
icon,
size,
steps,
tips,
media: { steps: true, result },
docs,
related,
}),
)
return {
guides,
context: {
id: spec.id,
parent: spec.parent,
route: spec.route,
icon: spec.icon,
bullets: spec.bullets,
guides: guides.map(g => g.id),
docs: spec.docs,
hero: spec.hero ?? true,
},
}
}