import React, { useEffect } from "react"; import { HashRouter as Router, Routes, Route, useSearchParams, useLocation, } from "react-router-dom"; import { ThemeProvider } from "@mui/material/styles"; import { Box, CssBaseline } from "@mui/material"; import Navigation from "./components/Navigation/Navigation"; import LeaderboardPage from "./pages/LeaderboardPage/LeaderboardPage"; import AddModelPage from "./pages/AddModelPage/AddModelPage"; import QuotePage from "./pages/QuotePage/QuotePage"; import VoteModelPage from "./pages/VoteModelPage/VoteModelPage"; import Footer from "./components/Footer/Footer"; import getTheme from "./config/theme"; import { useThemeMode } from "./hooks/useThemeMode"; import { QueryClient, QueryClientProvider } from "@tanstack/react-query"; import LeaderboardProvider from "./pages/LeaderboardPage/components/Leaderboard/context/LeaderboardContext"; const queryClient = new QueryClient({ defaultOptions: { queries: { retry: 1, refetchOnWindowFocus: false, }, }, }); function UrlHandler() { const location = useLocation(); const [searchParams] = useSearchParams(); // Synchroniser l'URL avec la page parente HF useEffect(() => { // VĂ©rifier si nous sommes dans un iframe HF Space const isHFSpace = window.location !== window.parent.location; if (!isHFSpace) return; // Sync query and hash from this embedded app to the parent page URL const queryString = window.location.search; const hash = window.location.hash; // HF Spaces' special message type to update the query string and the hash in the parent page URL window.parent.postMessage( { queryString, hash, }, "https://huggingface.co" ); }, [location, searchParams]); // Read the updated hash reactively useEffect(() => { const handleHashChange = (event) => { console.log("hash change event", event); }; window.addEventListener("hashchange", handleHashChange); return () => window.removeEventListener("hashchange", handleHashChange); }, []); return null; } function App() { const { mode, toggleTheme } = useThemeMode(); const theme = getTheme(mode); return (
} /> } /> } /> } />
); } export default App;