From c03c3a45347f1d2034a56a5f85d1cdef2834084e Mon Sep 17 00:00:00 2001 From: whidix Date: Sun, 8 Mar 2026 21:36:44 +0100 Subject: [PATCH] feat: update step navigation to use step order instead of IDs --- .../game/play/[sessionCode]/+layout.server.ts | 16 ++++++++-------- .../game/play/[sessionCode]/+layout.svelte | 8 ++++---- .../(game)/game/play/[sessionCode]/+page.svelte | 12 +----------- 3 files changed, 13 insertions(+), 23 deletions(-) diff --git a/src/routes/(game)/game/play/[sessionCode]/+layout.server.ts b/src/routes/(game)/game/play/[sessionCode]/+layout.server.ts index 31de47b..dd5fa7d 100644 --- a/src/routes/(game)/game/play/[sessionCode]/+layout.server.ts +++ b/src/routes/(game)/game/play/[sessionCode]/+layout.server.ts @@ -71,21 +71,21 @@ export const load: LayoutServerLoad = async ({ params, url }) => { ? steps.filter((entry) => entry.order <= currentStep.order) : steps; - const requestedStepId = Number.parseInt(url.searchParams.get('step') ?? '', 10); - const isRequestedStepUnlocked = unlockedSteps.some((entry) => entry.id === requestedStepId); + const requestedStepOrder = Number.parseInt(url.searchParams.get('step') ?? '', 10); + const isRequestedStepUnlocked = unlockedSteps.some((entry) => entry.order === requestedStepOrder); const displayedStepRecord = isRequestedStepUnlocked - ? (unlockedSteps.find((entry) => entry.id === requestedStepId) ?? null) + ? (unlockedSteps.find((entry) => entry.order === requestedStepOrder) ?? null) : (currentStep ?? unlockedSteps.at(-1) ?? null); const displayedStepIndex = displayedStepRecord ? unlockedSteps.findIndex((entry) => entry.id === displayedStepRecord.id) : -1; - const previousStepId = displayedStepIndex > 0 ? unlockedSteps[displayedStepIndex - 1].id : null; - const nextStepId = + const previousStepOrder = displayedStepIndex > 0 ? unlockedSteps[displayedStepIndex - 1].order : null; + const nextStepOrder = displayedStepIndex >= 0 && displayedStepIndex < unlockedSteps.length - 1 - ? unlockedSteps[displayedStepIndex + 1].id + ? unlockedSteps[displayedStepIndex + 1].order : null; return { @@ -114,8 +114,8 @@ export const load: LayoutServerLoad = async ({ params, url }) => { title: entry.title, isCompleted: completedStepIds.has(entry.id) })), - previousStepId, - nextStepId, + previousStepOrder, + nextStepOrder, collectedItems: session.collectedItems.map((entry) => ({ id: entry.item.id, name: entry.item.name, diff --git a/src/routes/(game)/game/play/[sessionCode]/+layout.svelte b/src/routes/(game)/game/play/[sessionCode]/+layout.svelte index ef86570..e1e71fb 100644 --- a/src/routes/(game)/game/play/[sessionCode]/+layout.svelte +++ b/src/routes/(game)/game/play/[sessionCode]/+layout.svelte @@ -91,9 +91,9 @@ - {#if data.previousStepId} + {#if data.previousStepOrder}
- +