scoresaber-reloaded-v2/src/store/IndexedDBStorage.ts

26 lines
797 B
TypeScript
Raw Normal View History

"use client";
2023-10-23 09:06:58 +00:00
import { createStore, del, get, set, UseStore } from "idb-keyval";
import { StateStorage } from "zustand/middleware";
2023-10-23 09:06:58 +00:00
let storage: UseStore | undefined = undefined;
if (typeof window !== "undefined") {
storage = createStore("scoresaber-reloaded", "scoresaber");
}
2023-10-23 09:03:57 +00:00
export const IDBStorage: StateStorage = {
getItem: async (name: string): Promise<string | null> => {
//console.log(name, "has been retrieved");
2023-10-23 09:03:57 +00:00
return (await get(name, storage)) || null;
},
setItem: async (name: string, value: string): Promise<void> => {
//console.log(name, "with value", value, "has been saved");
2023-10-23 09:03:57 +00:00
await set(name, value, storage);
},
removeItem: async (name: string): Promise<void> => {
//console.log(name, "has been deleted");
2023-10-23 09:03:57 +00:00
await del(name, storage);
},
};