import { lazy, Suspense, useEffect, useState } from "react"; import { Lock, RefreshCw } from "lucide-react"; import type { PublicAuthorData } from "./types"; const PortfolioPage = lazy(() => import("./components/PortfolioPage")); const AdminPanel = lazy(() => import("./components/AdminPanel")); function LoadingScreen() { return (

Portfolio wird geladen...

); } export default function App() { const [publicData, setPublicData] = useState(null); const [loading, setLoading] = useState(true); const [currentPath, setCurrentPath] = useState(window.location.pathname); const isAdmin = currentPath === "/admin" || currentPath.startsWith("/admin/"); useEffect(() => { const handleLocationChange = () => setCurrentPath(window.location.pathname); window.addEventListener("popstate", handleLocationChange); return () => window.removeEventListener("popstate", handleLocationChange); }, []); useEffect(() => { if (isAdmin) { setLoading(false); return; } const controller = new AbortController(); setLoading(true); fetch("/api/author-data", { signal: controller.signal }) .then((res) => { if (!res.ok) throw new Error(`HTTP ${res.status}`); return res.json() as Promise; }) .then((data) => setPublicData(data)) .catch((error) => { if (error instanceof DOMException && error.name === "AbortError") return; console.error("Fehler beim Abrufen des Portfolios:", error); setPublicData(null); }) .finally(() => setLoading(false)); return () => controller.abort(); }, [isAdmin]); useEffect(() => { if (isAdmin) document.title = "Administration"; else if (publicData) document.title = publicData.profile.seoTitle || publicData.profile.name; else document.title = "Portfolio"; }, [isAdmin, publicData]); const navigateTo = (path: string) => { window.history.pushState({}, "", path); setCurrentPath(path); }; if (isAdmin) { return ( }> navigateTo("/")} /> ); } if (loading) return ; if (!publicData) { return (

Verbindungsfehler

Das Portfolio konnte nicht geladen werden.

); } return ( }> ); }