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

48 lines
1.0 KiB
TypeScript
Raw Permalink Normal View History

2023-06-15 13:06:41 +00:00
import {Component, type JSX} from "preact";
import {
fromStorage,
StorageKey,
type StorageValues,
} from "../../storage/common.js";
import {allTours} from "../../tours/exports.js";
2023-06-15 13:06:41 +00:00
import {Tour} from "./tour.js";
type Props = Record<string, unknown>;
type State = {
toursCompleted: Awaited<StorageValues[StorageKey.ToursCompleted]>;
2023-06-15 13:06:41 +00:00
};
export class Tours extends Component<Props, State> {
constructor(props: Props) {
super(props);
this.state = {
toursCompleted: undefined!,
2023-06-15 13:06:41 +00:00
};
}
async componentDidMount(): Promise<void> {
const toursCompleted = await fromStorage(StorageKey.ToursCompleted);
this.setState({toursCompleted});
2023-06-15 13:06:41 +00:00
}
render(): JSX.Element {
const {toursCompleted} = this.state;
if (toursCompleted === undefined) {
return <></>;
}
2023-06-15 13:06:41 +00:00
const tours = allTours.map((tour) => (
<Tour hasBeenCompleted={toursCompleted.value.has(tour.id)} tour={tour} />
));
2023-06-15 13:06:41 +00:00
return (
<main>
<h2>Tours</h2>
<div class="tours">{tours}</div>
2023-06-15 13:06:41 +00:00
</main>
);
}
}