Skip to content

Commit d1aa817

Browse files
committed
feat: refactor InstructionsWizard to improve reset functionality and enhance UI layout; add undo icon to action buttons
1 parent 2a081fb commit d1aa817

File tree

1 file changed

+66
-61
lines changed

1 file changed

+66
-61
lines changed

components/instructions-wizard.tsx

Lines changed: 66 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import { useMemo, useState } from "react"
44
import { Button } from "@/components/ui/button"
5+
import { Undo2 } from "lucide-react"
56
import * as simpleIcons from "simple-icons"
67
import type { SimpleIcon } from "simple-icons"
78

@@ -504,7 +505,7 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
504505
advanceToNextQuestion()
505506
}, 0)
506507
}
507-
const resetWizard = () => {
508+
const resetWizardState = () => {
508509
setResponses({})
509510
setDynamicSteps([])
510511
setCurrentStepIndex(0)
@@ -514,6 +515,16 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
514515
setIsGenerating(false)
515516
}
516517

518+
const resetWizard = () => {
519+
if (onClose) {
520+
resetWizardState()
521+
onClose()
522+
return
523+
}
524+
525+
resetWizardState()
526+
}
527+
517528
const requestResetWizard = () => {
518529
setPendingConfirmation("reset")
519530
}
@@ -781,75 +792,70 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
781792
: undefined
782793
const showChangeFile = Boolean(onClose && selectedFile)
783794

784-
const actionBar = (
785-
<section className="rounded-2xl border border-border/70 bg-background/90 p-4 shadow-sm">
786-
<div className="flex flex-wrap items-center gap-3">
787-
<div className="flex flex-wrap gap-2">
788-
<Button
789-
variant="outline"
790-
onClick={goToPrevious}
791-
disabled={backDisabled}
792-
>
793-
Back
794-
</Button>
795-
<Button
796-
variant="ghost"
797-
onClick={() => void applyDefaultAnswer()}
798-
disabled={!canUseDefault}
799-
title={defaultButtonTitle}
800-
>
801-
{defaultButtonLabel}
802-
</Button>
803-
</div>
804-
<div className="ml-auto flex flex-wrap justify-end gap-2">
805-
<Button variant="destructive" onClick={requestResetWizard}>
806-
Start Over
807-
</Button>
808-
{showChangeFile ? (
809-
<Button variant="secondary" onClick={requestChangeFile}>
810-
Change File
811-
</Button>
812-
) : null}
813-
</div>
814-
</div>
815-
</section>
816-
)
817-
818795
const wizardLayout = (
819796
<div className="mx-auto flex w-full max-w-4xl flex-col gap-6">
797+
<Button
798+
variant="destructive"
799+
size="sm"
800+
onClick={requestResetWizard}
801+
className="fixed left-4 top-4 z-40"
802+
>
803+
Start Over
804+
</Button>
805+
820806
{selectedFile ? (
821807
<section className="rounded-3xl border border-border/70 bg-secondary/20 p-5 shadow-sm">
822-
<div className="flex flex-wrap items-start justify-between gap-4">
808+
<div className="flex flex-wrap items-center gap-3">
823809
<div>
824-
<p className="text-xs font-semibold uppercase tracking-wide text-muted-foreground">Instructions file</p>
825-
<p className="mt-1 text-lg font-semibold text-foreground">{selectedFile.label}</p>
826-
{selectedFile.filename ? (
827-
<p className="text-sm text-muted-foreground">{selectedFile.filename}</p>
828-
) : null}
810+
<p className="text-lg font-semibold text-foreground">
811+
{selectedFile.filename ?? selectedFile.label}
812+
</p>
829813
</div>
814+
{showChangeFile ? (
815+
<Button variant="outline" size="sm" onClick={requestChangeFile}>
816+
Change File
817+
</Button>
818+
) : null}
830819
</div>
831820
</section>
832821
) : null}
833822

834-
{actionBar}
835-
836823
{isComplete ? (
837824
renderCompletion()
838825
) : (
839-
<>
840-
<header className="flex items-start justify-between gap-4">
826+
<section className="rounded-3xl border border-border/80 bg-card/95 p-6 shadow-lg">
827+
<div className="flex flex-col gap-4">
828+
<div className="flex flex-wrap items-center gap-2">
829+
<Button
830+
variant="secondary"
831+
className="px-5"
832+
onClick={goToPrevious}
833+
disabled={backDisabled}
834+
>
835+
<Undo2 className="h-4 w-4" />
836+
Back
837+
</Button>
838+
<Button
839+
variant="outline"
840+
onClick={() => void applyDefaultAnswer()}
841+
disabled={!canUseDefault}
842+
title={defaultButtonTitle}
843+
>
844+
{defaultButtonLabel}
845+
</Button>
846+
</div>
847+
841848
<h1 className="text-3xl font-semibold text-foreground">
842849
{currentQuestion.question}
843850
</h1>
844-
</header>
845-
846-
<section className="rounded-3xl border border-border/80 bg-card/95 p-6 shadow-md">
847-
<div className="grid gap-3 sm:grid-cols-2">
848-
{currentQuestion.answers.map((answer) => {
849-
const iconDescriptor = getIconDescriptor(answer.icon ?? answer.value)
850-
const iconHex = iconDescriptor
851-
? iconColorOverrides[iconDescriptor.slug] ?? iconDescriptor.hex
852-
: undefined
851+
</div>
852+
853+
<div className="mt-6 grid gap-3 sm:grid-cols-2">
854+
{currentQuestion.answers.map((answer) => {
855+
const iconDescriptor = getIconDescriptor(answer.icon ?? answer.value)
856+
const iconHex = iconDescriptor
857+
? iconColorOverrides[iconDescriptor.slug] ?? iconDescriptor.hex
858+
: undefined
853859
const iconColor = iconHex ? getAccessibleIconColor(iconHex) : undefined
854860
const iconBackgroundColor = iconColor ? hexToRgba(iconColor, 0.18) : null
855861
const iconRingColor = iconColor ? hexToRgba(iconColor, 0.32) : null
@@ -907,15 +913,14 @@ export function InstructionsWizard({ onClose, selectedFileId }: InstructionsWiza
907913
/>
908914
)
909915
})}
910-
</div>
916+
</div>
911917

912-
<div className="mt-6 flex items-center justify-end">
913-
<div className="text-xs text-muted-foreground">
914-
Question {questionNumber} of {totalQuestions}
915-
</div>
918+
<div className="mt-6 flex items-center justify-end">
919+
<div className="text-xs text-muted-foreground">
920+
Question {questionNumber} of {totalQuestions}
916921
</div>
917-
</section>
918-
</>
922+
</div>
923+
</section>
919924
)}
920925

921926
{pendingConfirmation ? (

0 commit comments

Comments
 (0)