1
Fork 0

Always run the introduction tour if it hasn't happened yet and...

also run any specified tours afterwards.
This commit is contained in:
Bauke 2023-06-17 15:01:26 +02:00
parent de3c21db01
commit 4a875d4eff
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 18 additions and 8 deletions

View File

@ -8,20 +8,25 @@ import {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> {
// Automatically start the introduction tour if the person hasn't already been
// through it and only when on the Tildes homepage.
const introductionUnderstood = await createIntroductionUnderstood(); const introductionUnderstood = await createIntroductionUnderstood();
if (!introductionUnderstood.value && window.location.pathname === "/") {
startTour("introduction", introductionSteps, []);
return;
}
// Get the anchor without the leading #. // Get the anchor without the leading #.
const anchor = window.location.hash.slice(1); const anchor = window.location.hash.slice(1);
// We only care about anchors with our prefix. // We only care about anchors with our prefix.
const prefix = "tildes-shepherd-tour="; const prefix = "tildes-shepherd-tour=";
if (!anchor.startsWith(prefix)) { const startsWithPrefix = anchor.startsWith(prefix);
// Automatically start the introduction tour if the person hasn't already
// been through it and only when on the Tildes homepage.
if (!introductionUnderstood.value && window.location.pathname === "/") {
// If a different tour is selected but the introduction hasn't happened yet,
// then the main function will be rerun once this tour finishes.
startTour("introduction", introductionSteps, [], startsWithPrefix);
return;
}
if (!startsWithPrefix) {
return; return;
} }
@ -32,7 +37,7 @@ async function main(): Promise<void> {
// ID. // ID.
for (const [id, steps, eventHandlers] of tourIdsAndSteps) { for (const [id, steps, eventHandlers] of tourIdsAndSteps) {
if (anchorTourId === id) { if (anchorTourId === id) {
startTour(id, steps, eventHandlers); startTour(id, steps, eventHandlers, false);
return; return;
} }
} }
@ -50,6 +55,7 @@ function startTour(
tourId: TourId, tourId: TourId,
steps: TourStepOptions[], steps: TourStepOptions[],
eventHandlers: TourStepEventHandler[], eventHandlers: TourStepEventHandler[],
runMainAgainAfterComplete: boolean,
): void { ): void {
const tour = new Shepherd.Tour({ const tour = new Shepherd.Tour({
defaultStepOptions: { defaultStepOptions: {
@ -92,6 +98,10 @@ function startTour(
// Mark the tour as completed. // Mark the tour as completed.
await addCompletedTour(tourId); await addCompletedTour(tourId);
if (runMainAgainAfterComplete) {
await main();
}
}); });
// For every step we have, add it to the tour and subsequently add all the // For every step we have, add it to the tour and subsequently add all the