Add Oudelaa dashboard API integration
فشلت بعض الفحوصات
Deploy To Ghaymah / deploy (push) Has been cancelled

هذا الالتزام موجود في:
boutmoun123
2026-05-25 20:36:52 +03:00
الأصل 367fce6557
التزام 8863f61d00
90 ملفات معدلة مع 16694 إضافات و1 حذوفات

عرض الملف

@@ -0,0 +1,49 @@
"use client";
import { createContext, useContext, useEffect, useState } from "react";
export type Theme = "dark" | "light";
type ThemeContextValue = {
theme: Theme;
toggle: () => void;
};
const ThemeContext = createContext<ThemeContextValue | null>(null);
const STORAGE_KEY = "oudelaa.theme";
function applyTheme(theme: Theme) {
if (typeof document === "undefined") return;
const root = document.documentElement;
root.classList.remove("theme-dark", "theme-light");
root.classList.add(`theme-${theme}`);
}
export function ThemeProvider({ children }: { children: React.ReactNode }) {
const [theme, setTheme] = useState<Theme>("dark");
useEffect(() => {
const stored = window.localStorage.getItem(STORAGE_KEY) as Theme | null;
const initial = stored ?? "dark";
setTheme(initial);
applyTheme(initial);
}, []);
const toggle = () => {
setTheme((prev) => {
const next = prev === "dark" ? "light" : "dark";
window.localStorage.setItem(STORAGE_KEY, next);
applyTheme(next);
return next;
});
};
return <ThemeContext.Provider value={{ theme, toggle }}>{children}</ThemeContext.Provider>;
}
export function useTheme() {
const ctx = useContext(ThemeContext);
if (!ctx) throw new Error("useTheme must be used within ThemeProvider");
return ctx;
}