1
Fork 0
tildes-shepherd/source/options/components/tour.tsx

91 lines
2.1 KiB
TypeScript
Raw Normal View History

2023-06-15 13:06:41 +00:00
import {Component, type JSX} from "preact";
2023-07-01 10:41:54 +00:00
import {TourId} from "../../tours/exports.js";
2023-06-15 13:06:41 +00:00
type Props = {
hasBeenCompleted: boolean;
name: string;
tourId: TourId;
};
function tourDescription(tourId: Props["tourId"]): JSX.Element {
2023-07-01 10:41:54 +00:00
if (tourId === TourId.Introduction) {
2023-06-15 13:06:41 +00:00
return (
<p class="tour-description">
A short introduction to Tildes Shepherd and how the tours work. Normally
this is automatically shown when you first installed the extension.
</p>
);
}
2023-07-01 10:41:54 +00:00
if (tourId === TourId.InterfaceHomepage) {
2023-06-15 13:06:41 +00:00
return (
<p class="tour-description">
Let's take a look at the home page and all we can do there.
</p>
);
}
if (tourId === TourId.InterfaceAccountSettings) {
return (
<p class="tour-description">
View your account settings and all that you can customize.
</p>
);
}
2023-06-15 13:06:41 +00:00
return (
<p class="tour-description">
Tour ID "{tourId}" does not have a description, this should probably be
fixed!
</p>
);
}
function tourLink(tourId: Props["tourId"]): string {
const anchor = `#tildes-shepherd-tour=${tourId}`;
const baseUrl = "https://tildes.net";
let path = "";
switch (tourId) {
2023-07-01 10:41:54 +00:00
case TourId.InterfaceHomepage:
case TourId.Introduction: {
2023-06-15 13:06:41 +00:00
path = "/";
break;
}
case TourId.InterfaceAccountSettings: {
path = "/settings";
break;
}
default: {
throw new Error(`Unswitched tour ID: ${tourId as string}`);
}
2023-06-15 13:06:41 +00:00
}
return `${baseUrl}${path}${anchor}`;
}
export class Tour extends Component<Props> {
render() {
const {hasBeenCompleted, name, tourId} = this.props;
const classes = ["tour", hasBeenCompleted ? "completed" : ""].join(" ");
const completed = hasBeenCompleted ? (
<p class="tour-completed" title="You've completed this tour before!">
</p>
) : undefined;
return (
<div class={classes.trim()}>
<h3>{name}</h3>
{completed}
{tourDescription(tourId)}
<p class="tour-link">
<a href={tourLink(tourId)}>Take this tour</a>
</p>
</div>
);
}
}