From b04d1f06eb1f1a9e8fb01491b2641c23cc5d89fb Mon Sep 17 00:00:00 2001 From: neoapps-dev Date: Tue, 5 May 2026 14:12:52 +0300 Subject: [PATCH] fix: branch cycling logic --- src/hooks/useGameManager.ts | 17 +++++++++++------ 1 file changed, 11 insertions(+), 6 deletions(-) diff --git a/src/hooks/useGameManager.ts b/src/hooks/useGameManager.ts index d6a29f5..394807d 100644 --- a/src/hooks/useGameManager.ts +++ b/src/hooks/useGameManager.ts @@ -178,15 +178,20 @@ export function useGameManager({ if (available.length <= 1) return; setSelectedBranches(prev => { const current = prev[editionId] || available[0]; - const currentIndex = available.indexOf(current); - const nextIndex = (currentIndex + 1) % available.length; - const nextBranch = available[nextIndex]; - const oldInstanceId = current === "Stable" ? editionId : `${editionId}_${current}`; - const newInstanceId = nextBranch === "Stable" ? editionId : `${editionId}_${nextBranch}`; + let currentIndex = available.indexOf(current); + let nextIndex = currentIndex; + let nextBranch = current; + do { + nextIndex = (nextIndex + 1) % available.length; + nextBranch = available[nextIndex]; + } while (nextBranch.startsWith("v") && nextIndex !== currentIndex); + const oldInstanceId = + current === "Stable" ? editionId : `${editionId}_${current}`; + const newInstanceId = + nextBranch === "Stable" ? editionId : `${editionId}_${nextBranch}`; if (profile === oldInstanceId) { setProfile(newInstanceId); } - return { ...prev, [editionId]: nextBranch }; }); }, [branches, profile, setProfile]);