mirror of
https://github.com/arthur-pbty/portfolio.git
synced 2026-08-01 20:29:43 +02:00
- Reduced the number of photos displayed from 68 to 33 in the photo gallery. - Removed unused photo files (photos 34 to 68) from the public directory. - Updated Docker configuration for better environment management and container naming. - Upgraded Next.js and ESLint dependencies to their latest versions. - Added ESLint configuration file for improved code quality checks. - Introduced a .dockerignore file to exclude unnecessary files from the Docker context. - Added an example .env file for environment variable configuration. Co-authored-by: Copilot <copilot@github.com>
51 lines
1.1 KiB
TypeScript
51 lines
1.1 KiB
TypeScript
"use client";
|
|
|
|
import { createContext, useContext, useEffect, useState } from "react";
|
|
|
|
type Theme = "dark" | "light";
|
|
|
|
const ThemeContext = createContext<{
|
|
theme: Theme;
|
|
toggleTheme: () => void;
|
|
}>({
|
|
theme: "dark",
|
|
toggleTheme: () => {},
|
|
});
|
|
|
|
// safe getter (évite SSR crash)
|
|
function getInitialTheme(): Theme {
|
|
if (typeof window === "undefined") {return "dark";}
|
|
|
|
return (
|
|
(localStorage.getItem("theme") as Theme) ||
|
|
(document.documentElement.getAttribute("data-theme") as Theme) ||
|
|
"dark"
|
|
);
|
|
}
|
|
|
|
export default function ThemeProvider({
|
|
children,
|
|
}: {
|
|
children: React.ReactNode;
|
|
}) {
|
|
const [theme, setTheme] = useState<Theme>(() => getInitialTheme());
|
|
|
|
useEffect(() => {
|
|
document.documentElement.setAttribute("data-theme", theme);
|
|
localStorage.setItem("theme", theme);
|
|
}, [theme]);
|
|
|
|
const toggleTheme = () => {
|
|
setTheme((prev) => (prev === "dark" ? "light" : "dark"));
|
|
};
|
|
|
|
return (
|
|
<ThemeContext.Provider value={{ theme, toggleTheme }}>
|
|
{children}
|
|
</ThemeContext.Provider>
|
|
);
|
|
}
|
|
|
|
export function useTheme() {
|
|
return useContext(ThemeContext);
|
|
} |