From bec153c282ae10de88f25284a5e5790b56fe4b42 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Wed, 22 Nov 2023 12:14:35 +0100 Subject: [PATCH] Updated the Calculate.jsx state --- .../src/pages/Game/states/Calculate/Calculate.jsx | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/client/src/pages/Game/states/Calculate/Calculate.jsx b/client/src/pages/Game/states/Calculate/Calculate.jsx index 9f6054b..63728be 100644 --- a/client/src/pages/Game/states/Calculate/Calculate.jsx +++ b/client/src/pages/Game/states/Calculate/Calculate.jsx @@ -19,7 +19,7 @@ const localeOptions = { } export const Calculate = ({setState, currentRound}) => { - const {round, getGroupById, updateCapital, endRound} = useContext(GroupContext); + const {round, getGroupById, updateCapital, endRound, setRoundHistory} = useContext(GroupContext); const {rounds} = useContext(SettingsContext); @@ -41,10 +41,12 @@ export const Calculate = ({setState, currentRound}) => { let profit = sold * current.price - (current.amount * 1000 + 4000); - setAnimatedGroups(old => [...old, {...current, profit, name: getGroupById(current.id).name, sold, - newCapital: getGroupById(current.id).capital + profit}]); + let currentRound = {...current, profit, name: getGroupById(current.id).name, sold, + newCapital: getGroupById(current.id).capital + profit}; - updateCapital(current.id, getGroupById(current.id).capital + profit); + setAnimatedGroups(old => [...old, currentRound]); + + updateCapital(current.id, currentRound.newCapital); } useEffect(() => { @@ -63,6 +65,8 @@ export const Calculate = ({setState, currentRound}) => { useEffect(() => { if (animatedGroups.length === 0) return; + setRoundHistory(history => [...history, animatedGroups]); + const timeout = setTimeout(() => { setShowNewCapital(true); }, 3000); @@ -144,7 +148,7 @@ export const Calculate = ({setState, currentRound}) => { {showNewCapital && currentRound >= rounds &&