2023-06-15 12:56:59 +00:00
|
|
|
import browser from "webextension-polyfill";
|
|
|
|
import {createValue} from "@holllo/webextension-storage";
|
2023-07-01 10:41:54 +00:00
|
|
|
import {type TourId} from "../tours/exports.js";
|
2023-06-15 12:56:59 +00:00
|
|
|
|
|
|
|
export enum StorageKey {
|
|
|
|
IntroductionUnderstood = "introduction-understood",
|
|
|
|
ToursCompleted = "tours-completed",
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createIntroductionUnderstood() {
|
|
|
|
return createValue<boolean>({
|
|
|
|
deserialize: (input) => input === "true",
|
|
|
|
serialize: (input) => JSON.stringify(input),
|
|
|
|
key: StorageKey.IntroductionUnderstood,
|
|
|
|
storage: browser.storage.local,
|
|
|
|
value: false,
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function createToursCompleted() {
|
|
|
|
return createValue<Set<TourId>>({
|
|
|
|
deserialize: (input) => new Set(JSON.parse(input) as TourId[]),
|
|
|
|
serialize: (input) => JSON.stringify(Array.from(input)),
|
|
|
|
key: StorageKey.ToursCompleted,
|
|
|
|
storage: browser.storage.local,
|
|
|
|
value: new Set([]),
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
|
|
|
export async function addCompletedTour(tourId: TourId): Promise<void> {
|
|
|
|
const toursCompleted = await createToursCompleted();
|
|
|
|
toursCompleted.value.add(tourId);
|
|
|
|
await toursCompleted.save();
|
|
|
|
}
|