1
0

Updated the Calculate.jsx state

This commit is contained in:
Mathias Wagner 2023-11-22 12:14:35 +01:00
parent 96d79be828
commit bec153c282
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -19,7 +19,7 @@ const localeOptions = {
} }
export const Calculate = ({setState, currentRound}) => { export const Calculate = ({setState, currentRound}) => {
const {round, getGroupById, updateCapital, endRound} = useContext(GroupContext); const {round, getGroupById, updateCapital, endRound, setRoundHistory} = useContext(GroupContext);
const {rounds} = useContext(SettingsContext); const {rounds} = useContext(SettingsContext);
@ -41,10 +41,12 @@ export const Calculate = ({setState, currentRound}) => {
let profit = sold * current.price - (current.amount * 1000 + 4000); let profit = sold * current.price - (current.amount * 1000 + 4000);
setAnimatedGroups(old => [...old, {...current, profit, name: getGroupById(current.id).name, sold, let currentRound = {...current, profit, name: getGroupById(current.id).name, sold,
newCapital: getGroupById(current.id).capital + profit}]); newCapital: getGroupById(current.id).capital + profit};
updateCapital(current.id, getGroupById(current.id).capital + profit); setAnimatedGroups(old => [...old, currentRound]);
updateCapital(current.id, currentRound.newCapital);
} }
useEffect(() => { useEffect(() => {
@ -63,6 +65,8 @@ export const Calculate = ({setState, currentRound}) => {
useEffect(() => { useEffect(() => {
if (animatedGroups.length === 0) return; if (animatedGroups.length === 0) return;
setRoundHistory(history => [...history, animatedGroups]);
const timeout = setTimeout(() => { const timeout = setTimeout(() => {
setShowNewCapital(true); setShowNewCapital(true);
}, 3000); }, 3000);
@ -144,7 +148,7 @@ export const Calculate = ({setState, currentRound}) => {
{showNewCapital && currentRound >= rounds && <Button text="Spiel beenden" onClick={() => navigate("/end")} icon={faStop}/>} {showNewCapital && currentRound >= rounds && <Button text="Spiel beenden" onClick={() => navigate("/end")} icon={faStop}/>}
</div> </div>
</div> </div>
<div className="glassy customer" style={{marginTop: (6.2 * animatedGroups.length) + "rem"}}> <div className="glassy customer" style={{marginTop: (6.2 * animatedGroups.length + 5.2) + "rem"}}>
<FontAwesomeIcon icon={faShoppingCart} /> <FontAwesomeIcon icon={faShoppingCart} />
<div className="customer-item"> <div className="customer-item">
<p>Nachfrage</p> <p>Nachfrage</p>