tfrere commited on
Commit
60de3d1
·
1 Parent(s): 2405b72

update footer year and update dark mode behavior

Browse files
client/index.html CHANGED
@@ -11,6 +11,18 @@
11
  rel="stylesheet"
12
  />
13
  <title>Leaderboards on the Hub</title>
 
 
 
 
 
 
 
 
 
 
 
 
14
  </head>
15
  <body>
16
  <div id="root"></div>
 
11
  rel="stylesheet"
12
  />
13
  <title>Leaderboards on the Hub</title>
14
+ <script>
15
+ // Detect system preference for dark mode and apply it immediately
16
+ // This prevents flash of wrong theme on initial load
17
+ (function () {
18
+ var prefersDarkMode =
19
+ window.matchMedia &&
20
+ window.matchMedia("(prefers-color-scheme: dark)").matches;
21
+ var theme = prefersDarkMode ? "dark" : "light";
22
+ document.documentElement.setAttribute("data-theme", theme);
23
+ document.documentElement.classList.add(theme + "-mode");
24
+ })();
25
+ </script>
26
  </head>
27
  <body>
28
  <div id="root"></div>
client/src/App.jsx CHANGED
@@ -1,4 +1,4 @@
1
- import React from "react";
2
  import { HashRouter as Router, Routes, Route } from "react-router-dom";
3
  import { ThemeProvider } from "@mui/material/styles";
4
  import { Box, CssBaseline } from "@mui/material";
@@ -13,6 +13,21 @@ function App() {
13
  const { mode, toggleTheme } = useThemeMode();
14
  const theme = getTheme(mode);
15
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
16
  return (
17
  <div
18
  className="App"
 
1
+ import React, { useEffect } from "react";
2
  import { HashRouter as Router, Routes, Route } from "react-router-dom";
3
  import { ThemeProvider } from "@mui/material/styles";
4
  import { Box, CssBaseline } from "@mui/material";
 
13
  const { mode, toggleTheme } = useThemeMode();
14
  const theme = getTheme(mode);
15
 
16
+ // Clean up any theme-related localStorage entries on initial load
17
+ useEffect(() => {
18
+ localStorage.removeItem("theme-mode");
19
+ }, []);
20
+
21
+ // Apply theme to document as early as possible
22
+ useEffect(() => {
23
+ // Apply theme class to document body
24
+ document.body.classList.remove("light-mode", "dark-mode");
25
+ document.body.classList.add(`${mode}-mode`);
26
+
27
+ // This helps prevent flash of wrong theme
28
+ document.documentElement.setAttribute("data-theme", mode);
29
+ }, [mode]);
30
+
31
  return (
32
  <div
33
  className="App"
client/src/components/Footer/Footer.jsx CHANGED
@@ -12,8 +12,8 @@ const Footer = () => {
12
  }}
13
  >
14
  <Typography variant="body2" color="text.secondary" sx={{ mx: 4 }}>
15
- © 2024 Hugging Face - Leaderboards on the hub - Made with 🤗 by the HF
16
- team -{" "}
17
  <Link
18
  href="https://huggingface.co"
19
  target="_blank"
 
12
  }}
13
  >
14
  <Typography variant="body2" color="text.secondary" sx={{ mx: 4 }}>
15
+ © {new Date().getFullYear()} Hugging Face - Leaderboards on the hub -
16
+ Made with 🤗 by the HF team -{" "}
17
  <Link
18
  href="https://huggingface.co"
19
  target="_blank"
client/src/hooks/useThemeMode.js CHANGED
@@ -1,18 +1,53 @@
1
  import { useState, useEffect } from "react";
2
 
3
  export const useThemeMode = () => {
4
- const [mode, setMode] = useState(() => {
5
- const savedMode = localStorage.getItem("theme-mode");
6
- return savedMode || "light";
7
- });
 
 
 
 
 
 
8
 
 
9
  useEffect(() => {
10
- localStorage.setItem("theme-mode", mode);
11
- }, [mode]);
 
 
 
12
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
13
  const toggleTheme = () => {
14
  setMode((prevMode) => (prevMode === "light" ? "dark" : "light"));
15
  };
16
 
17
- return { mode, toggleTheme };
 
 
 
 
18
  };
 
1
  import { useState, useEffect } from "react";
2
 
3
  export const useThemeMode = () => {
4
+ // Function to detect system preference for dark mode
5
+ const getSystemPreference = () => {
6
+ return window.matchMedia &&
7
+ window.matchMedia("(prefers-color-scheme: dark)").matches
8
+ ? "dark"
9
+ : "light";
10
+ };
11
+
12
+ // Initialize state with system preference
13
+ const [mode, setMode] = useState(getSystemPreference());
14
 
15
+ // Listen for changes in system preference
16
  useEffect(() => {
17
+ const mediaQuery = window.matchMedia("(prefers-color-scheme: dark)");
18
+
19
+ const handleChange = (e) => {
20
+ setMode(e.matches ? "dark" : "light");
21
+ };
22
 
23
+ // Add event listener
24
+ if (mediaQuery.addEventListener) {
25
+ mediaQuery.addEventListener("change", handleChange);
26
+ } else {
27
+ // For older browsers
28
+ mediaQuery.addListener(handleChange);
29
+ }
30
+
31
+ // Cleanup
32
+ return () => {
33
+ if (mediaQuery.removeEventListener) {
34
+ mediaQuery.removeEventListener("change", handleChange);
35
+ } else {
36
+ // For older browsers
37
+ mediaQuery.removeListener(handleChange);
38
+ }
39
+ };
40
+ }, []);
41
+
42
+ // Toggle function is kept for compatibility with existing code
43
+ // but it will only temporarily change the theme until the next system preference change
44
  const toggleTheme = () => {
45
  setMode((prevMode) => (prevMode === "light" ? "dark" : "light"));
46
  };
47
 
48
+ return {
49
+ mode,
50
+ toggleTheme,
51
+ isSystemPreference: true,
52
+ };
53
  };
client/src/main.jsx CHANGED
@@ -1,46 +1,10 @@
1
  import { StrictMode } from "react";
2
  import { createRoot } from "react-dom/client";
3
- import { ThemeProvider, createTheme } from "@mui/material/styles";
4
- import { CssBaseline } from "@mui/material";
5
  import "./index.css";
6
  import App from "./App.jsx";
7
 
8
- // Créer un thème personnalisé
9
- const theme = createTheme({
10
- typography: {
11
- fontFamily: '"Source Sans Pro", sans-serif',
12
- h1: {
13
- fontFamily: '"Source Sans Pro", sans-serif',
14
- },
15
- h2: {
16
- fontFamily: '"Source Sans Pro", sans-serif',
17
- },
18
- h3: {
19
- fontFamily: '"Source Sans Pro", sans-serif',
20
- },
21
- h4: {
22
- fontFamily: '"Source Sans Pro", sans-serif',
23
- },
24
- h5: {
25
- fontFamily: '"Source Sans Pro", sans-serif',
26
- },
27
- h6: {
28
- fontFamily: '"Source Sans Pro", sans-serif',
29
- },
30
- body1: {
31
- fontFamily: '"Source Sans Pro", sans-serif',
32
- },
33
- body2: {
34
- fontFamily: '"Source Sans Pro", sans-serif',
35
- },
36
- },
37
- });
38
-
39
  createRoot(document.getElementById("root")).render(
40
  <StrictMode>
41
- <ThemeProvider theme={theme}>
42
- <CssBaseline />
43
- <App />
44
- </ThemeProvider>
45
  </StrictMode>
46
  );
 
1
  import { StrictMode } from "react";
2
  import { createRoot } from "react-dom/client";
 
 
3
  import "./index.css";
4
  import App from "./App.jsx";
5
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
6
  createRoot(document.getElementById("root")).render(
7
  <StrictMode>
8
+ <App />
 
 
 
9
  </StrictMode>
10
  );