Skip to content

Commit 0ca5e53

Browse files
authored
Merge pull request #11 from spivx/add-more-stacks
feat: Implement loading fallback and enhance wizard page with Suspens…
2 parents 097a291 + 000f9c6 commit 0ca5e53

File tree

3 files changed

+29
-11
lines changed

3 files changed

+29
-11
lines changed

app/new/page.tsx

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
"use client"
22

3-
import { useMemo, useState } from "react"
3+
import { Suspense, useMemo, useState } from "react"
44

55
import { Button } from "@/components/ui/button"
66
import { InstructionsWizard } from "@/components/instructions-wizard"
@@ -21,6 +21,14 @@ const fileQuestion = fileQuestionSet[0] ?? null
2121
const fileOptionsFromData = buildFileOptionsFromQuestion(fileQuestion)
2222

2323
export default function NewInstructionsPage() {
24+
return (
25+
<Suspense fallback={<LoadingFallback />}>
26+
<NewInstructionsPageContent />
27+
</Suspense>
28+
)
29+
}
30+
31+
function NewInstructionsPageContent() {
2432
const searchParams = useSearchParams()
2533
const [showWizard, setShowWizard] = useState(false)
2634
const [selectedFileId, setSelectedFileId] = useState<string | null>(null)
@@ -125,3 +133,11 @@ export default function NewInstructionsPage() {
125133
</div>
126134
)
127135
}
136+
137+
function LoadingFallback() {
138+
return (
139+
<div className="flex min-h-screen items-center justify-center bg-background text-sm text-muted-foreground">
140+
Loading wizard…
141+
</div>
142+
)
143+
}

components/instructions-wizard.tsx

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ import { useCallback, useEffect, useMemo, useRef, useState } from "react"
44
import { Button } from "@/components/ui/button"
55
import { Undo2 } from "lucide-react"
66

7-
import type { DataQuestionSource, FileOutputConfig, InstructionsWizardProps, Responses, WizardAnswer, WizardConfirmationIntent, WizardQuestion, WizardStep } from "@/types/wizard"
7+
import type { DataQuestionSource, InstructionsWizardProps, Responses, WizardAnswer, WizardConfirmationIntent, WizardQuestion, WizardStep } from "@/types/wizard"
88
import { buildFilterPlaceholder, useAnswerFilter } from "@/hooks/use-answer-filter"
99
import stacksData from "@/data/stacks.json"
1010
import generalData from "@/data/general.json"
@@ -189,7 +189,7 @@ export function InstructionsWizard({ onClose, selectedFileId, initialStackId }:
189189
responses,
190190
autoFilledQuestionMap
191191
),
192-
[fileSummaryQuestion, selectedFile, selectedFileFormatLabel, wizardSteps, responses, autoFilledQuestionMap]
192+
[selectedFile, selectedFileFormatLabel, wizardSteps, responses, autoFilledQuestionMap]
193193
)
194194

195195
const currentAnswerValue = currentQuestion ? responses[currentQuestion.id] : undefined
@@ -258,20 +258,18 @@ export function InstructionsWizard({ onClose, selectedFileId, initialStackId }:
258258
setActiveEditQuestionId(null)
259259
}, [])
260260

261-
if (!currentStep || !currentQuestion) {
262-
return null
263-
}
264-
265261
const isAnswerSelected = (value: string) => {
266-
if (currentQuestion.allowMultiple) {
262+
if (currentQuestion?.allowMultiple) {
267263
return Array.isArray(currentAnswerValue) && currentAnswerValue.includes(value)
268264
}
269265

270266
return currentAnswerValue === value
271267
}
272268

273269
const advanceToNextQuestion = () => {
274-
const isLastQuestionInStep = currentQuestionIndex === currentStep.questions.length - 1
270+
const currentStepForAdvance = wizardSteps[currentStepIndex]
271+
const isLastQuestionInStep =
272+
currentStepForAdvance ? currentQuestionIndex === currentStepForAdvance.questions.length - 1 : false
275273
const isLastStep = currentStepIndex === wizardSteps.length - 1
276274

277275
if (isLastQuestionInStep && isLastStep) {
@@ -390,6 +388,10 @@ export function InstructionsWizard({ onClose, selectedFileId, initialStackId }:
390388
void loadStackQuestions(stackAnswer.value, stackAnswer.label)
391389
}, [initialStackId, loadStackQuestions])
392390

391+
if (!currentStep || !currentQuestion) {
392+
return null
393+
}
394+
393395
const applyDefaultsAcrossWizard = () => {
394396
setGeneratedFile(null)
395397
setAutoFilledQuestionMap({})
@@ -807,7 +809,7 @@ export function InstructionsWizard({ onClose, selectedFileId, initialStackId }:
807809

808810
{showNoFilterMatches ? (
809811
<p className="mt-6 rounded-xl border border-border/70 bg-muted/30 px-4 py-6 text-sm text-muted-foreground">
810-
No options match "{answerFilterQuery}". Try a different search.
812+
No options match &ldquo;{answerFilterQuery}&rdquo;. Try a different search.
811813
</p>
812814
) : (
813815
<WizardAnswerGrid

components/wizard-edit-answer-dialog.tsx

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ export function WizardEditAnswerDialog({ question, value, onAnswerSelect, onClos
6565

6666
{showNoMatches ? (
6767
<p className="rounded-xl border border-border/70 bg-muted/30 px-4 py-6 text-sm text-muted-foreground">
68-
No options match "{query}". Try a different search.
68+
No options match &ldquo;{query}&rdquo;. Try a different search.
6969
</p>
7070
) : (
7171
<WizardAnswerGrid answers={answers} onAnswerClick={onAnswerSelect} isSelected={isSelected} />

0 commit comments

Comments
 (0)