mirror of
https://github.com/Radiquum/AniX.git
synced 2025-04-06 00:04:39 +00:00
fix: check store hydration before loading pages fix: check user store before loading pages
56 lines
1.2 KiB
TypeScript
56 lines
1.2 KiB
TypeScript
"use client";
|
|
import { create } from "zustand";
|
|
import { persist } from "zustand/middleware";
|
|
|
|
interface preferencesState {
|
|
_hasHydrated: boolean;
|
|
flags: {
|
|
// saveSearchHistory: boolean;
|
|
saveWatchHistory: boolean;
|
|
// theme: "light" | "dark" | "black" | "system";
|
|
};
|
|
params: {
|
|
isFirstLaunch: boolean;
|
|
// color: {
|
|
// primary: string;
|
|
// secondary: string;
|
|
// accent: string;
|
|
// }
|
|
};
|
|
setHasHydrated: (state: boolean) => void;
|
|
setFlags: (flags: preferencesState["flags"]) => void;
|
|
setParams: (params: preferencesState["params"]) => void;
|
|
}
|
|
|
|
export const usePreferencesStore = create<preferencesState>()(
|
|
persist(
|
|
(set, get) => ({
|
|
_hasHydrated: false,
|
|
flags: {
|
|
// saveSearchHistory: true,
|
|
saveWatchHistory: true,
|
|
// theme: "light",
|
|
},
|
|
params: {
|
|
isFirstLaunch: true,
|
|
},
|
|
setHasHydrated: (state) => {
|
|
set({
|
|
_hasHydrated: state,
|
|
});
|
|
},
|
|
setFlags(flags) {
|
|
set({ flags });
|
|
},
|
|
setParams(params) {
|
|
set({ params });
|
|
},
|
|
}),
|
|
{
|
|
name: "preferences",
|
|
onRehydrateStorage: (state) => {
|
|
return () => state.setHasHydrated(true);
|
|
},
|
|
}
|
|
)
|
|
);
|