feat: refactor

This commit is contained in:
2024-01-12 20:32:45 +07:00
parent 67c6177291
commit 0487b8a801
63 changed files with 345 additions and 777 deletions

View File

@@ -0,0 +1,29 @@
import { locale, platform } from "@tauri-apps/plugin-os";
import Database from "@tauri-apps/plugin-sql";
import { PropsWithChildren, createContext, useContext } from "react";
import { LumeStorage } from "./storage";
const StorageContext = createContext<LumeStorage>(null);
const sqliteAdapter = await Database.load("sqlite:lume_v3.db");
const platformName = await platform();
const osLocale = await locale();
const db = new LumeStorage(sqliteAdapter, platformName, osLocale);
await db.init();
if (db.settings.depot) await db.launchDepot();
export const StorageProvider = ({ children }: PropsWithChildren<object>) => {
return (
<StorageContext.Provider value={db}>{children}</StorageContext.Provider>
);
};
export const useStorage = () => {
const context = useContext(StorageContext);
if (context === undefined) {
throw new Error("Please import Storage Provider to use useStorage() hook");
}
return context;
};