From 01b4de1cfd8a6b95800a7f8d791fb7dd72b75327 Mon Sep 17 00:00:00 2001 From: Konstantin Chaika Date: Wed, 28 Aug 2024 15:39:43 +0200 Subject: [PATCH] Disable buttons when action is performed --- .../components/screens/MainActionsScreen.tsx | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/culinaryFrontend/src/components/screens/MainActionsScreen.tsx b/culinaryFrontend/src/components/screens/MainActionsScreen.tsx index eab473e..ef31de2 100644 --- a/culinaryFrontend/src/components/screens/MainActionsScreen.tsx +++ b/culinaryFrontend/src/components/screens/MainActionsScreen.tsx @@ -109,6 +109,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr let [saladBowlOptions, setSaladBowlOptions] = useState(initialSaladBowlOptions); let [berryBasketOptions, setBerryBasketOptions] = useState(initialBerryBasketOptions); let [citrusBasketOptions, setCitrusBasketOptions] = useState(initialCitrusBasketOptions); + let [buttonBlocker, setButtonBlocker] = useState(""); function berryBasketVisSetter(value: boolean){ setBerryBasketOptions(prevOptions => ({ @@ -519,6 +520,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr setBerryBasketOptions(initialBerryBasketOptions) spicesShelfVisSetter(false) counterProductsSetter([]) + setButtonBlocker("cook") const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); @@ -528,6 +530,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr console.log("GOT: " + actions) if (actions.length == 0){ infoTextSetter("Not enough vegetables to make soup!") + setButtonBlocker("") return } infoTextSetter("Let's go!") @@ -543,10 +546,12 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr await delay(1500); } infoTextSetter("Cooking is done!") + setButtonBlocker("") }) } function spice() { + setButtonBlocker("spice") const delay = (ms: number) => new Promise(res => setTimeout(res, ms)); let actions = Array() @@ -555,6 +560,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr console.log("GOT: " + actions) if (actions.length == 0){ infoTextSetter("You need to cook the soup first!") + setButtonBlocker("") return } infoTextSetter("Let's add some spices!") @@ -570,6 +576,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr await delay(1500); } infoTextSetter("Adding the spices is done!") + setButtonBlocker("") }) } @@ -585,6 +592,10 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr }) } + function shouldShow(buttonName: string){ + return !buttonBlocker; + } + return (
@@ -620,19 +631,19 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr }