import { render } from "preact"; import { useMemo, useState } from "preact/hooks"; import "./index.css"; const CARD_VALUES = [ { label: "J", pts: 2 }, { label: "Q", pts: 3 }, { label: "K", pts: 4 }, { label: "3", pts: 10 }, { label: "A", pts: 11 }, ]; function TeamScore({ id, score, total, counts, opponentCounts, onAdd, reverse, }) { return (
T{id} {score}
TOTAL
{total}
{CARD_VALUES.map((v, i) => ( ))}
); } function ScorerView({ s1, s2, total1, total2, c1, c2, onAdd, onClear, onSave, }) { return (
); } function HistoryView({ history, onPurge }) { return (
{history.map((r, i) => { const h1 = history .slice(0, i + 1) .reduce((a, b) => a + b.t1, 0); const h2 = history .slice(0, i + 1) .reduce((a, b) => a + b.t2, 0); return ( ); })}
# T1 T2 CUMUL
{i + 1} {r.t1} {r.t2} {h1} / {h2}
); } // --- Main App --- export function App() { const [tab, setTab] = useState("score"); const [s1, setS1] = useState(0); const [s2, setS2] = useState(0); const [c1, setC1] = useState([0, 0, 0, 0, 0]); const [c2, setC2] = useState([0, 0, 0, 0, 0]); const [history, setHistory] = useState([]); const histT1 = useMemo( () => history.reduce((a, b) => a + b.t1, 0), [history], ); const histT2 = useMemo( () => history.reduce((a, b) => a + b.t2, 0), [history], ); const add = (team, idx, pts) => { if (c1[idx] + c2[idx] >= 4) return; if (team === 1) { setS1((v) => v + pts); setC1((v) => { const n = [...v]; n[idx]++; return n; }); } else { setS2((v) => v + pts); setC2((v) => { const n = [...v]; n[idx]++; return n; }); } }; const clearRound = () => { setS1(0); setS2(0); setC1([0, 0, 0, 0, 0]); setC2([0, 0, 0, 0, 0]); }; const save = () => { if (s1 === 0 && s2 === 0) return; setHistory((prev) => [...prev, { t1: s1, t2: s2 }]); clearRound(); }; return (
{tab === "score" ? ( ) : ( confirm("purge?") && setHistory([])} /> )}
); } render(, document.getElementById("app")); // todo: central buttons animations