Files
HellreigN/frontend/src/modules/theme-bw/stores/theme.store.ts
T
nikitaa_ts 8cf0837f97
ci-front / build (push) Successful in 2m3s
fix: themes and layout
2026-04-04 00:01:01 +03:00

36 lines
1.1 KiB
TypeScript

import type { Theme } from "@/modules/auth/types/auth.types";
import { create } from "zustand";
import { persist } from "zustand/middleware";
import { applyTheme, getSavedTheme, getCurrentTheme } from "@/modules/theme-changer/utils/apply.theme";
interface ThemeState {
theme: Theme;
toggleTheme: () => void;
setTheme: (theme: Theme) => void;
}
export const useThemeStore = create<ThemeState>()(
persist(
(set, get) => ({
theme: "dark" as Theme,
toggleTheme: () => {
const currentTheme = getCurrentTheme();
const newThemeType = currentTheme === "dark" || currentTheme === "nightowl" || currentTheme === "sunset" || currentTheme === "forest" || currentTheme === "ocean" || currentTheme === "coffee"
? "light"
: "dark";
// Переключаемся между light и dark базовыми темами
const newTheme = newThemeType === "dark" ? "dark" : "light";
applyTheme(newTheme);
set({ theme: newTheme as Theme });
},
setTheme: (theme: Theme) => {
applyTheme(theme);
set({ theme });
},
}),
{
name: "theme-storage",
},
),
);