Skip to content

Commit a02541d

Browse files
committed
fix: next step button
1 parent 281d117 commit a02541d

File tree

1 file changed

+8
-4
lines changed

1 file changed

+8
-4
lines changed

src/App.tsx

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@ function App() {
2323
)
2424
const [pendingStep, setPendingStep] = useState(false)
2525

26-
// Create a new packet for the current step
2726
const createPacketForStep = useCallback((step: number) => {
2827
const newPacket = getPacketForStep(step)
2928
if (!newPacket) return null
@@ -32,7 +31,6 @@ function App() {
3231
return newPacket
3332
}, [])
3433

35-
// Start or continue animation
3634
const startAnimation = useCallback(() => {
3735
if (currentStep >= TOTAL_STEPS) {
3836
setIsPlaying(false)
@@ -64,7 +62,10 @@ function App() {
6462
}
6563

6664
const handleStepForward = () => {
67-
if (currentStep < TOTAL_STEPS && !isPlaying) {
65+
if (currentStep >= TOTAL_STEPS) return
66+
if (currentPacket) {
67+
handlePacketComplete() // Instantly finish the current animation and move to the next step
68+
} else {
6869
setPendingStep(true)
6970
setInfoText(getInfoText(currentStep))
7071
createPacketForStep(currentStep)
@@ -83,9 +84,12 @@ function App() {
8384

8485
const handlePacketComplete = useCallback(() => {
8586
setCurrentPacket(null)
86-
if (isPlaying || pendingStep) {
87+
setLayerInfo('')
88+
if (pendingStep) {
8789
setCurrentStep((prev) => prev + 1)
8890
setPendingStep(false)
91+
} else if (isPlaying) {
92+
setCurrentStep((prev) => prev + 1)
8993
}
9094
}, [isPlaying, pendingStep])
9195

0 commit comments

Comments
 (0)