From 84c6d265cf3df3943f14683098da7f5643cce357 Mon Sep 17 00:00:00 2001 From: c0mrade Date: Wed, 4 Feb 2026 00:22:46 +0300 Subject: [PATCH] Fix drag-and-drop multiple reorders and wheel lights pattern - Allow multiple prize reorders before saving by using current displayed order - Simplify lights pattern calculation using distance-based logic - Fixes: drag only worked once, lights appeared to go through wheel --- src/components/wheel/FortuneWheel.tsx | 11 ++++------- src/pages/AdminWheel.tsx | 15 +++++++++++---- 2 files changed, 15 insertions(+), 11 deletions(-) diff --git a/src/components/wheel/FortuneWheel.tsx b/src/components/wheel/FortuneWheel.tsx index 547dc89..110c094 100644 --- a/src/components/wheel/FortuneWheel.tsx +++ b/src/components/wheel/FortuneWheel.tsx @@ -62,13 +62,10 @@ const FortuneWheel = memo(function FortuneWheel({ const numLights = isSpinning ? 3 : 4; // 3 lights when spinning, 4 when idle return Array.from({ length: 20 }, (_, i) => { - // Check if this light index is within the active range - for (let j = 0; j < numLights; j++) { - if (i === (lightPhase + j) % 20) { - return true; - } - } - return false; + // Calculate distance from current lightPhase + const distance = (i - lightPhase + 20) % 20; + // Light is on if within range [0, numLights) + return distance < numLights; }); }, [isSpinning, lightPhase]); diff --git a/src/pages/AdminWheel.tsx b/src/pages/AdminWheel.tsx index 461ec81..61a2493 100644 --- a/src/pages/AdminWheel.tsx +++ b/src/pages/AdminWheel.tsx @@ -427,17 +427,24 @@ export default function AdminWheel() { onTelegramDragEnd(); const { active, over } = event; if (over && active.id !== over.id && config) { - const oldIndex = config.prizes.findIndex((p) => p.id === active.id); - const newIndex = config.prizes.findIndex((p) => p.id === over.id); + // Use current displayed order (either local or from config) + const currentPrizes = localPrizeOrder + ? localPrizeOrder + .map((id) => config.prizes.find((p) => p.id === id)) + .filter((p): p is WheelPrizeAdmin => p !== undefined) + : config.prizes; + + const oldIndex = currentPrizes.findIndex((p) => p.id === active.id); + const newIndex = currentPrizes.findIndex((p) => p.id === over.id); if (oldIndex !== -1 && newIndex !== -1) { - const newOrder = arrayMove(config.prizes, oldIndex, newIndex); + const newOrder = arrayMove(currentPrizes, oldIndex, newIndex); // Save order locally, don't trigger mutation immediately setLocalPrizeOrder(newOrder.map((p) => p.id)); setHasUnsavedOrder(true); } } }, - [config, onTelegramDragEnd], + [config, localPrizeOrder, onTelegramDragEnd], ); // Save prize order