const { useState: useStateApp, useEffect: useEffectApp } = React; const TWEAK_DEFAULTS = { confetti: true, suits: true }; // Read first path segment from URL (/samawar → "samawar", / → null) function getSlug() { const path = window.location.pathname.replace(/^\/|\/$/g, ""); if (!path) return null; return path.split("/")[0].toLowerCase(); } // ── Main router ─────────────────────────────────────────────── function App() { const slug = getSlug(); if (!slug) { return (
); } return ; } // ── Group app (existing single-group app, now slug-aware) ───── function GroupApp({ slug }) { const [page, setPage] = useStateApp("landing"); const [profileId, setProfileId] = useStateApp(1); const [tweaks, setTweaks] = useStateApp(TWEAK_DEFAULTS); const [confetti, setConfetti] = useStateApp(false); const [tick, setTick] = useStateApp(0); useEffectApp(() => { const unsub = DB.subscribe(() => setTick(t => t + 1)); DB.load(slug); return unsub; }, [slug]); function openProfile(id) { setProfileId(id); setPage("profile"); } function nav(p) { setPage(p); } function fireConfetti() { setConfetti(false); requestAnimationFrame(() => setConfetti(true)); } // ── Loading ── if (DB.loading && !DB.raw) { return (
جاري التحميل…
); } // ── Group not found ── if (DB.error === "not-found") { return (
مجموعة غير موجودة
«{slug}» مش موجودة عندنا
← الرئيسية
); } // ── Other error ── if (DB.error) { return (
خطأ في الاتصال
{DB.error}
); } const NAV_ITEMS = [ { id: "leaderboard", label: "الأبطال", icon: "♛" }, { id: "history", label: "المباريات", icon: "♦" }, { id: "profile", label: "البروفايل", icon: "♥" }, { id: "admin", label: "إدارة", icon: "♠" }, ]; return (
{tweaks.suits && } {/* Desktop sidebar — hidden on mobile via CSS */} {page !== "landing" && ( )} {/* Page content */}
{page === "landing" && setPage("leaderboard")} />} {page === "leaderboard" && } {page === "profile" && setPage("leaderboard")} />} {page === "history" && } {page === "admin" && { setPage("leaderboard"); fireConfetti(); }} />}
{/* Mobile bottom nav — hidden on desktop via CSS */} {page !== "landing" && } {tweaks.confetti && setConfetti(false)} />}
); } const root = ReactDOM.createRoot(document.getElementById("root")); root.render();