1
Fork 0

Refactor TourId to be an enum.

This commit is contained in:
Bauke 2023-07-01 12:41:54 +02:00
parent 1b063e6e90
commit 48742a9864
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
6 changed files with 18 additions and 14 deletions

View File

@ -4,7 +4,7 @@ import {
createIntroductionUnderstood, createIntroductionUnderstood,
} from "../storage/common.js"; } from "../storage/common.js";
import {introductionSteps} from "../tours/introduction.js"; import {introductionSteps} from "../tours/introduction.js";
import {tourIdsAndSteps} from "../tours/exports.js"; import {TourId, tourIdsAndSteps} from "../tours/exports.js";
/** The main entry point for the content script. */ /** The main entry point for the content script. */
async function main(): Promise<void> { async function main(): Promise<void> {
@ -26,7 +26,7 @@ async function main(): Promise<void> {
// If a different tour is selected but the introduction hasn't happened yet, // If a different tour is selected but the introduction hasn't happened yet,
// then the main function will be rerun once this tour finishes. // then the main function will be rerun once this tour finishes.
startTour( startTour(
"introduction", TourId.Introduction,
introductionSteps, introductionSteps,
[], [],
startsWithPrefix && anchorTourId !== "introduction", startsWithPrefix && anchorTourId !== "introduction",

View File

@ -1,4 +1,5 @@
import {Component, type JSX} from "preact"; import {Component, type JSX} from "preact";
import {TourId} from "../../tours/exports.js";
type Props = { type Props = {
hasBeenCompleted: boolean; hasBeenCompleted: boolean;
@ -7,7 +8,7 @@ type Props = {
}; };
function tourDescription(tourId: Props["tourId"]): JSX.Element { function tourDescription(tourId: Props["tourId"]): JSX.Element {
if (tourId === "introduction") { if (tourId === TourId.Introduction) {
return ( return (
<p class="tour-description"> <p class="tour-description">
A short introduction to Tildes Shepherd and how the tours work. Normally A short introduction to Tildes Shepherd and how the tours work. Normally
@ -16,7 +17,7 @@ function tourDescription(tourId: Props["tourId"]): JSX.Element {
); );
} }
if (tourId === "interface-homepage") { if (tourId === TourId.InterfaceHomepage) {
return ( return (
<p class="tour-description"> <p class="tour-description">
Let's take a look at the home page and all we can do there. Let's take a look at the home page and all we can do there.
@ -38,8 +39,8 @@ function tourLink(tourId: Props["tourId"]): string {
let path = ""; let path = "";
switch (tourId) { switch (tourId) {
case "interface-homepage": case TourId.InterfaceHomepage:
case "introduction": { case TourId.Introduction: {
path = "/"; path = "/";
break; break;
} }

View File

@ -1,5 +1,6 @@
import {Component, type JSX} from "preact"; import {Component, type JSX} from "preact";
import {createToursCompleted} from "../../storage/common.js"; import {createToursCompleted} from "../../storage/common.js";
import {TourId} from "../../tours/exports.js";
import {Tour} from "./tour.js"; import {Tour} from "./tour.js";
type Props = Record<string, unknown>; type Props = Record<string, unknown>;
@ -34,8 +35,8 @@ export class Tours extends Component<Props, State> {
}; };
const tourProps: Array<Tour["props"]> = [ const tourProps: Array<Tour["props"]> = [
createTour("introduction", "Introduction"), createTour(TourId.Introduction, "Introduction"),
createTour("interface-homepage", "The Homepage"), createTour(TourId.InterfaceHomepage, "The Homepage"),
]; ];
return ( return (

View File

@ -1,5 +1,6 @@
import browser from "webextension-polyfill"; import browser from "webextension-polyfill";
import {createValue} from "@holllo/webextension-storage"; import {createValue} from "@holllo/webextension-storage";
import {type TourId} from "../tours/exports.js";
export enum StorageKey { export enum StorageKey {
IntroductionUnderstood = "introduction-understood", IntroductionUnderstood = "introduction-understood",

View File

@ -1,11 +1,14 @@
import {homepageSteps, homepageEventHandlers} from "./interface/exports.js"; import {homepageEventHandlers, homepageSteps} from "./interface/exports.js";
import {introductionSteps} from "./introduction.js"; import {introductionSteps} from "./introduction.js";
export const tourIds = ["introduction", "interface-homepage"] as const; export enum TourId {
InterfaceHomepage = "interface-homepage",
Introduction = "introduction",
}
export const tourIdsAndSteps: Array< export const tourIdsAndSteps: Array<
[TourId, TourStepOptions[], TourStepEventHandler[]] [TourId, TourStepOptions[], TourStepEventHandler[]]
> = [ > = [
["introduction", introductionSteps, []], [TourId.Introduction, introductionSteps, []],
["interface-homepage", homepageSteps, homepageEventHandlers], [TourId.InterfaceHomepage, homepageSteps, homepageEventHandlers],
]; ];

2
source/types.d.ts vendored
View File

@ -1,12 +1,10 @@
import type Shepherd from "shepherd.js"; import type Shepherd from "shepherd.js";
import type {tourIds} from "./tours/exports.js";
declare global { declare global {
const $browser: "chromium" | "firefox"; const $browser: "chromium" | "firefox";
const $dev: boolean; const $dev: boolean;
const $test: boolean; const $test: boolean;
type TourId = (typeof tourIds)[number];
type TourStepEvent = "show" | "destroy"; type TourStepEvent = "show" | "destroy";
type TourStepEventFunction = Parameters<Shepherd.Step["on"]>[1]; type TourStepEventFunction = Parameters<Shepherd.Step["on"]>[1];
type TourStepEventHandler = [string, [TourStepEvent, TourStepEventFunction]]; type TourStepEventHandler = [string, [TourStepEvent, TourStepEventFunction]];