// piloto-publico.jsx — perfil público de un piloto (piloto.html?name=...). // Mismo contenido que "Mi Perfil" (perfil.jsx) pero de solo lectura y SIN la // biblioteca de logos, que es un recurso interno del staff/pilotos logueados. const { useState: useStateQ, useMemo: useMemoQ, useEffect: useEffectQ } = React; function PilotoPublico() { const params = new URLSearchParams(location.search); const name = params.get("name") || ""; const years = (() => { const ys = CDGX.pilotYears(name); return ys.length ? ys : [CDGX.years()[0]]; })(); const [year, setYear] = useStateQ(years[0]); const meta = CDGX.meta(name); const season = useMemoQ(() => CDGX.pilotSeason(name, year), [name, year]); const rkO = CDGX.rankOf(name, year, '5"'), rkT = CDGX.rankOf(name, year, "TINY"); const [extra, setExtra] = useStateQ({ multigp_id: null, photos: [], videos: [] }); const [modal, setModal] = useStateQ(null); const [toastMsg, setToastMsg] = useStateQ(""); const [toastErr, setToastErr] = useStateQ(false); function toast(m, isErr) { setToastMsg(m); setToastErr(!!isErr); } useEffectQ(() => { if (!toastMsg) return; const t = setTimeout(() => setToastMsg(""), 3200); return () => clearTimeout(t); }, [toastMsg]); // El "cálculo experto" es público: cualquiera que vea el perfil de un piloto // puede abrirlo, no solo el propio piloto logueado en Mi Perfil. const [view, setView] = useStateQ(location.hash === "#calculadora" ? "calc" : "perfil"); const [calcCat, setCalcCat] = useStateQ(null); useEffectQ(() => { const onHash = () => setView(location.hash === "#calculadora" ? "calc" : "perfil"); window.addEventListener("hashchange", onHash); return () => window.removeEventListener("hashchange", onHash); }, []); function openExpert(cat) { setCalcCat(cat); location.hash = "calculadora"; } function backToProfile() { location.hash = ""; } useEffectQ(() => { if (!name) return; fetch("public-pilot-profile.php?pilot=" + encodeURIComponent(name)) .then(r => r.json()).then(d => { if (d.ok) setExtra(d); }).catch(() => {}); }, [name]); if (!name || !season.length) { return (
No encontramos carreras de "{name || "—"}" en la temporada {year}.
← Volver al ranking