scoresaber-reloaded-v2/src/store/IndexedDBStorage.ts
Liam 9494fe599b
All checks were successful
deploy / deploy (push) Successful in 53s
goofy ahh nextjs
2023-10-23 10:06:58 +01:00

26 lines
797 B
TypeScript

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