2023-06-15 13:06:41 +00:00
|
|
|
import {Component, type JSX} from "preact";
|
2023-07-02 10:25:48 +00:00
|
|
|
import {
|
|
|
|
fromStorage,
|
|
|
|
StorageKey,
|
|
|
|
type StorageValues,
|
|
|
|
} from "../../storage/common.js";
|
2023-07-02 09:28:41 +00:00
|
|
|
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 = {
|
2023-07-02 10:25:48 +00:00
|
|
|
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 = {
|
2023-07-02 10:25:48 +00:00
|
|
|
toursCompleted: undefined!,
|
2023-06-15 13:06:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
async componentDidMount(): Promise<void> {
|
2023-07-02 10:25:48 +00:00
|
|
|
const toursCompleted = await fromStorage(StorageKey.ToursCompleted);
|
|
|
|
this.setState({toursCompleted});
|
2023-06-15 13:06:41 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
render(): JSX.Element {
|
|
|
|
const {toursCompleted} = this.state;
|
2023-07-02 10:25:48 +00:00
|
|
|
if (toursCompleted === undefined) {
|
|
|
|
return <></>;
|
|
|
|
}
|
2023-06-15 13:06:41 +00:00
|
|
|
|
2023-07-02 09:28:41 +00:00
|
|
|
const tours = allTours.map((tour) => (
|
2023-07-02 10:25:48 +00:00
|
|
|
<Tour hasBeenCompleted={toursCompleted.value.has(tour.id)} tour={tour} />
|
2023-07-02 09:28:41 +00:00
|
|
|
));
|
2023-06-15 13:06:41 +00:00
|
|
|
|
|
|
|
return (
|
|
|
|
<main>
|
|
|
|
<h2>Tours</h2>
|
2023-07-02 09:28:41 +00:00
|
|
|
<div class="tours">{tours}</div>
|
2023-06-15 13:06:41 +00:00
|
|
|
</main>
|
|
|
|
);
|
|
|
|
}
|
|
|
|
}
|