1
Fork 0

Add the storage logic.

This commit is contained in:
Bauke 2023-06-15 14:56:59 +02:00
parent 5c3d61679c
commit 4d600e200d
Signed by: Bauke
GPG Key ID: C1C0F29952BCF558
1 changed files with 33 additions and 0 deletions

33
source/storage/common.ts Normal file
View File

@ -0,0 +1,33 @@
import browser from "webextension-polyfill";
import {createValue} from "@holllo/webextension-storage";
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();
}