import React, { useState } from "react";
import { useLocation, useNavigate, useSearchParams } from "react-router-dom";
import {MainNavigation} from "@codegouvfr/react-dsfr/MainNavigation";
const Navigation = () => {
const location = useLocation();
const navigate = useNavigate();
const [active, setActive] = useState(0);
const [searchParams] = useSearchParams();
// Function to sync URL with parent HF page
const syncUrlWithParent = (queryString, hash) => {
// Check if we're in an HF Space iframe
const isHFSpace = window.location !== window.parent.location;
if (isHFSpace) {
try {
// Build complete URL with hash
const fullPath = `${queryString}${hash ? "#" + hash : ""}`;
window.parent.postMessage(
{
type: "urlUpdate",
path: fullPath,
},
"https://huggingface.co"
);
} catch (e) {
console.warn("Unable to sync URL with parent:", e);
}
}
};
const handleNavigation = (index, path) => (e) => {
e.preventDefault();
const searchString = searchParams.toString();
const queryString = searchString ? `?${searchString}` : "";
const newPath = `${path}${queryString}`;
// Local navigation via React Router
navigate(newPath);
// If in HF Space, sync with parent
if (window.location !== window.parent.location) {
syncUrlWithParent(queryString, newPath);
}
setActive(index);
};
return (
);
{/* Internal navigation */}
//
//
// Leaderboard
//
//
// Submit model
//
//
// Vote for next model
//
//
// Citations
//
//
//
// {/* External links */}
//
//
// Compare models
//
//
//
// About
//
//
//
//
// {/* Dark mode toggle */}
//
// ({
// color: "text.secondary",
// borderRadius: "100%",
// padding: 0,
// width: "36px",
// height: "36px",
// display: "flex",
// alignItems: "center",
// justifyContent: "center",
// transition: "all 0.2s ease-in-out",
// "&:hover": {
// color: "text.primary",
// backgroundColor: alpha(
// theme.palette.text.primary,
// theme.palette.mode === "dark" ? 0.1 : 0.06
// ),
// },
// "&.MuiButtonBase-root": {
// overflow: "hidden",
// },
// "& .MuiTouchRipple-root": {
// color: alpha(theme.palette.text.primary, 0.3),
// },
// })}
// >
// {mode === "light" ? (
//
// ) : (
//
// )}
//
//
//
// )}
//
//
// );
};
export default Navigation;