import { useState, useEffect } from "react"; import { Layout, Space } from "antd"; import { useLocation, useNavigate } from "react-router-dom"; import { AnimatePresence, motion } from "framer-motion"; import ParticlesBackground from "./components/ParticlesBackground"; import { useMediaQuery } from "react-responsive"; import { useKeycloak } from "./utils/KeycloakProvider"; import MainView from "./views/MainView"; import NotFoundView from "./views/NotFoundView"; import CVView from "./views/CVView"; import ContactView from "./views/ContactView"; import SocialsView from "./views/SocialsView"; import ExperienceView from "./views/ExperienceView"; import BlogsView from "./views/BlogsView"; import BlogView from "./views/BlogView"; import CacheReloadView from "./utils/CacheReloadView"; import { LoadingOutlined } from "@ant-design/icons"; const { Content } = Layout; const { Footer } = Layout; const App = () => { const location = useLocation(); // This gives you access to location object const navigate = useNavigate(); // To navigate programmatically const isMobile = useMediaQuery({ maxWidth: 600 }); const { isAuthenticated, loading, keycloak } = useKeycloak(); // Get the query parameter from the URL const getQueryParam = (param) => { const searchParams = new URLSearchParams(location.search); // Use location.search directly return searchParams.get(param) || "index"; // Default to "index" if param is not found }; // Initialize state with query parameters const [currentView, setCurrentView] = useState(getQueryParam("to")); const referrer = getQueryParam("r"); useEffect(() => { const queryParams = new URLSearchParams(); // Add the "to" parameter to the query queryParams.set("to", currentView); // If the referrer exists, add it to the query as well if (referrer) { queryParams.set("r", referrer); } // Navigate with the updated query string navigate(`?${queryParams.toString()}`); // Initial body setup to prevent scrollbars document.body.style.overflow = "hidden"; document.body.style.margin = "0"; document.body.style.padding = "0"; }, [currentView, referrer, navigate]); const fadeVariants = { initial: { clipPath: "polygon(0 0, 0 0, 0 100%, 0% 100%)", opacity: 0, }, animate: { clipPath: "polygon(0 0, 100% 0, 100% 100%, 0 100%)", opacity: 1, transition: { duration: 0.7, ease: "easeInOut", }, }, exit: { clipPath: "polygon(100% 0, 100% 0, 100% 100%, 100% 100%)", opacity: 0, transition: { duration: 0.7, ease: "easeInOut", }, }, }; // Render different views based on currentView state const renderView = () => { if (currentView.startsWith("blog-")) { const blogSlug = currentView.replace("blog-", ""); return ; } switch (currentView) { case "index": return ; case "cv": return ; case "experience": return ; case "blogs": return ; case "contact": return ; case "socials": return ( ); case "cacheReload": return ; default: return ; } }; return ( ); }; export default App;