From bd52ae071e3674face0cea76a1d631cedef00d83 Mon Sep 17 00:00:00 2001 From: batmanisko Date: Wed, 23 Sep 2026 16:18:11 +0200 Subject: [PATCH] =?UTF-8?q?fix:=20kolo=20=C5=A1t=C4=9Bst=C3=AD=20to=C4=8D?= =?UTF-8?q?=C3=AD=20a=C5=BE=20od=20dvou=20mo=C5=BEnost=C3=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../src/components/modals/SpinWheelModal.tsx | 24 +++++++++++++++---- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/client/src/components/modals/SpinWheelModal.tsx b/client/src/components/modals/SpinWheelModal.tsx index b984bc2..3a2c7eb 100644 --- a/client/src/components/modals/SpinWheelModal.tsx +++ b/client/src/components/modals/SpinWheelModal.tsx @@ -45,6 +45,8 @@ const WHEEL_SIZE = 360; const RADIUS = WHEEL_SIZE / 2 - 6; const SEGMENT_COLORS = 6; const MAX_LABELED_SEGMENTS = 40; +/** Točit má smysl až od dvou možností — jediná zbylá se vybere rovnou. */ +const MIN_SPIN_ITEMS = 2; /** Kryptograficky náhodný index v rozsahu 0..n-1 (bez modulo zkreslení to u malých n nevadí). */ function randomIndex(n: number): number { @@ -198,9 +200,17 @@ export default function SpinWheelModal({ isOpen, onClose, menus, onPick }: Reado setRotation(r => r % 360); }; + // Zbyla jediná možnost — není co losovat, vybere se rovnou (lze pokračovat dál / převzít) + const onlyOne = wheelItems.length === 1; + useEffect(() => { + if (spinning || !onlyOne) return; + if (phase === 'place' && place?.id !== places[0].id) setPlace(places[0]); + else if (phase === 'dish' && dish?.name !== dishes[0].name) setDish(dishes[0]); + }, [onlyOne, phase, places, dishes, spinning, place?.id, dish?.name]); + const spin = () => { const n = wheelItems.length; - if (n === 0 || spinning) return; + if (n < MIN_SPIN_ITEMS || spinning) return; const index = randomIndex(n); const angle = 360 / n; const jitter = (Math.random() - 0.5) * angle * 0.6; @@ -337,17 +347,21 @@ export default function SpinWheelModal({ isOpen, onClose, menus, onPick }: Reado )}
{result && (phase === 'place' - ? <>Padlo: {place!.label} ({place!.kind === 'menu' ? 'dnešní menu' : 'rozvoz'}) - : <>Padlo: {dish!.name}{dish!.price && ({dish!.price})})} + ? <>{onlyOne ? 'Zbývá jediná možnost' : 'Padlo'}: {place!.label} ({place!.kind === 'menu' ? 'dnešní menu' : 'rozvoz'}) + : <>{onlyOne ? 'Zbývá jediné jídlo' : 'Padlo'}: {dish!.name}{dish!.price && ({dish!.price})})}
- {result && !spinning && wheelItems.length > 1 && ( )}
+ {onlyOne && ( + Na kole musí být aspoň 2 možnosti — vrať nějaké vyřazené, nebo pokračuj s touto. + )}