Skip to content

Commit 0634fff

Browse files
committed
feat: enhance navigation logic in InstructionsWizard for improved step transitions
1 parent 3ddfa31 commit 0634fff

File tree

1 file changed

+23
-13
lines changed

1 file changed

+23
-13
lines changed

components/instructions-wizard.tsx

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -297,22 +297,32 @@ export function InstructionsWizard({
297297
setIsStackFastTrackPromptVisible(false)
298298
}
299299

300-
const isFirstQuestionInStep = currentQuestionIndex === 0
301-
const isFirstStep = currentStepIndex === 0
300+
setCurrentQuestionIndex((prevQuestionIndex) => {
301+
if (prevQuestionIndex > 0) {
302+
return prevQuestionIndex - 1
303+
}
302304

303-
if (isFirstQuestionInStep && isFirstStep) {
304-
return
305-
}
305+
let targetStepIndex = currentStepIndex
306306

307-
if (isFirstQuestionInStep) {
308-
const previousStepIndex = Math.max(currentStepIndex - 1, 0)
309-
const previousStep = wizardSteps[previousStepIndex]
310-
setCurrentStepIndex(previousStepIndex)
311-
setCurrentQuestionIndex(previousStep.questions.length - 1)
312-
return
313-
}
307+
setCurrentStepIndex((prevStepIndex) => {
308+
if (prevStepIndex === 0) {
309+
targetStepIndex = prevStepIndex
310+
return prevStepIndex
311+
}
314312

315-
setCurrentQuestionIndex((prev) => Math.max(prev - 1, 0))
313+
const nextStepIndex = Math.max(prevStepIndex - 1, 0)
314+
targetStepIndex = nextStepIndex
315+
return nextStepIndex
316+
})
317+
318+
const targetStep = wizardSteps[targetStepIndex] ?? null
319+
320+
if (targetStep && targetStep.questions.length > 0) {
321+
return targetStep.questions.length - 1
322+
}
323+
324+
return 0
325+
})
316326
}
317327

318328
const applyDefaultsAcrossWizard = useCallback(() => {

0 commit comments

Comments
 (0)