AniX/app/store/preferences.ts
Radiquum 5270c50c7b
Some checks failed
V3 Preview Deployment / Deploy-Preview (push) Has been cancelled
feat: add navbar title show options
2025-03-17 02:34:06 +05:00

82 lines
2 KiB
TypeScript

"use client";
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { deepmerge } from "deepmerge-ts";
interface preferencesState {
_hasHydrated: boolean;
flags: {
// saveSearchHistory: boolean;
saveWatchHistory?: boolean;
showChangelog?: boolean;
enableAnalytics?: boolean;
showNavbarTitles?: "always" | "links" | "selected" | "never";
};
params: {
isFirstLaunch?: boolean;
version?: string;
skipToCategory?: {
enabled: boolean;
homeCategory: string;
bookmarksCategory: string;
};
experimental?: {
newPlayer: 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,
showChangelog: true,
enableAnalytics: true,
showNavbarTitles: "always",
},
params: {
isFirstLaunch: true,
version: "3.0.0",
skipToCategory: {
enabled: false,
homeCategory: "last",
bookmarksCategory: "watching",
},
experimental: {
newPlayer: false
}
},
setHasHydrated: (state) => {
set({
_hasHydrated: state,
});
},
setFlags(flags) {
set({ flags: { ...get().flags, ...flags } });
},
setParams(params) {
set({ params: { ...get().params, ...params } });
},
}),
{
name: "preferences",
onRehydrateStorage: (state) => {
return () => state.setHasHydrated(true);
},
merge: (persistedState , currentState) => {
return deepmerge(currentState as preferencesState, persistedState as preferencesState);
}
}
)
);