Open History to see the last commit
1import { markSectionDone } from "@/components/guide/guide-store";
2import { matchesAppAction, subscribeToAppActions } from "@/lib/app-actions";
3import type { AppActionEvent } from "@/lib/app-actions";
4
5import { GUIDE_SECTIONS } from "./content";
6import type { GuideSectionContent } from "./content";
7
8/** The sections whose hands-on step `event` completes. */
9export function sectionsDoneBy(
10 event: AppActionEvent,
11 sections: Pick<GuideSectionContent, "id" | "doneWhen">[] = GUIDE_SECTIONS,
12): string[] {
13 return sections
14 .filter((section) => section.doneWhen?.some((matcher) => matchesAppAction(matcher, event)))
15 .map((section) => section.id);
16}
17
18/** Marks sections done as the reader does their steps in the app. Returns a stop function. */
19export function trackSectionProgress(): () => void {
20 return subscribeToAppActions((event) => {
21 for (const id of sectionsDoneBy(event)) markSectionDone(id);
22 });
23}