Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add JS actions for salad and smoothie #77

Merged
merged 1 commit into from
Sep 28, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
50 changes: 39 additions & 11 deletions culinaryFrontend/src/components/screens/MainActionsScreen.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,20 @@ type MainActionsScreenProps = {

export default function MainActionsScreen({gameStateSetter}: MainActionsScreenProps) {

const refillUrl = "/functions/refill-fridge"
const soupUrl = "/functions/tomato-soup"
const spiceUrl = "/functions/soup-spices"
const tasteUrl = "/functions/check-soup"
const refillUrl = "/functions/refill-fridge"
const soupUrl = "/functions/tomato-soup"
const spiceUrl = "/functions/soup-spices"
const tasteUrl = "/functions/check-soup"
const saladListUrl = "/functions/salad-list"
const saladSequenceUrl = "/functions/salad-sequence"
const smoothieListUrl = "/functions/smoothie-list"
const smoothieSequenceUrl = "/functions/smoothie-sequence"

const soupName = "soup"
const saladListName = "salad (list)"
const saladSequenceName = "salad (sequence)"
const smoothieListName = "smoothie (list)"
const smoothieSequenceName = "smoothie (sequence)"

type BlenderOptions = {
visible: boolean,
Expand Down Expand Up @@ -102,7 +112,7 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr

let [counterProducts, counterProductsSetter] = useState<Array<JsItemType>>([])
let [fridgeProducts, fridgeProductsSetter] = useState<Array<JsItemType>>([])
let [infoText, infoTextSetter] = useState<String>("Press \"Cook!\" button to start")
let [infoText, infoTextSetter] = useState<String>("Press button to start")
let [spicesShelfVis, spicesShelfVisSetter] = useState<boolean>(false)
let [blenderOptions, setBlenderOptions] = useState<BlenderOptions>(initialBlenderOptions);
let [potOptions, setPotOptions] = useState<PotOptions>(initialPotOptions);
Expand Down Expand Up @@ -512,24 +522,25 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr
})
}

function cook() {

function cook(url: string, dishName: string){
setBlenderOptions(initialBlenderOptions);
setPotOptions(initialPotOptions);
setSaladBowlOptions(initialSaladBowlOptions)
setCitrusBasketOptions(initialCitrusBasketOptions)
setBerryBasketOptions(initialBerryBasketOptions)
spicesShelfVisSetter(false)
counterProductsSetter([])
setButtonBlocker("cook")
setButtonBlocker(dishName)

const delay = (ms: number) => new Promise(res => setTimeout(res, ms));

let actions = Array<JsAction>()
axios.get(soupUrl).then(async (response) => {
axios.get(url).then(async (response) => {
actions = response.data as Array<JsAction>
console.log("GOT: " + actions)
if (actions.length == 0){
infoTextSetter("Not enough vegetables to make soup!")
infoTextSetter(`Not enough ingredients to make ${dishName}!`)
setButtonBlocker("")
return
}
Expand Down Expand Up @@ -635,8 +646,8 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr
onClick={() => refill()}>Refill!
</button>
<button
className={"App-button-base App-button-action " + (fridgeProducts.length > 0 && shouldShow("cook") ? "" : "App-button-disable")}
onClick={() => cook()}>Soup!
className={"App-button-base App-button-action " + (fridgeProducts.length > 0 && shouldShow(soupName) ? "" : "App-button-disable")}
onClick={() => cook(soupUrl, soupName)}>Soup!
</button>
<button
className={"App-button-base App-button-action " + (potOptions.soup && shouldShow("spice") ? "" : "App-button-disable")}
Expand All @@ -647,6 +658,23 @@ export default function MainActionsScreen({gameStateSetter}: MainActionsScreenPr
onClick={() => taste()}>Taste!
</button>

<button
className={"App-button-base App-button-action " + (shouldShow(saladListName) ? "" : "App-button-disable")}
onClick={() => cook(saladListUrl, saladListName)}>Sld list!
</button>
<button
className={"App-button-base App-button-action " + (shouldShow(saladSequenceName) ? "" : "App-button-disable")}
onClick={() => cook(saladSequenceUrl, saladSequenceName)}>Sld seq!
</button>
<button
className={"App-button-base App-button-action " + (shouldShow(smoothieListName) ? "" : "App-button-disable")}
onClick={() => cook(smoothieListUrl, smoothieListName)}>Smth list!
</button>
<button
className={"App-button-base App-button-action " + (shouldShow(smoothieSequenceName) ? "" : "App-button-disable")}
onClick={() => cook(smoothieSequenceUrl, smoothieSequenceName)}>Smth seq!
</button>

</div>
</div>
);
Expand Down
Loading