1
0

Updated the Calculate.jsx state

This commit is contained in:
Mathias Wagner 2023-11-23 07:51:23 +01:00
parent b1ee8b2213
commit 06f1c2eae8
Signed by: Mathias
GPG Key ID: B8DC354B0A1F5B44

View File

@ -21,7 +21,7 @@ const localeOptions = {
export const Calculate = ({setState, currentRound}) => { export const Calculate = ({setState, currentRound}) => {
const {round, getGroupById, updateCapital, endRound, setRoundHistory} = useContext(GroupContext); const {round, getGroupById, updateCapital, endRound, setRoundHistory} = useContext(GroupContext);
const {rounds, demandTable} = useContext(SettingsContext); const {rounds, demandTable, costPerCake, costPerRound} = useContext(SettingsContext);
const navigate = useNavigate(); const navigate = useNavigate();
@ -35,15 +35,16 @@ export const Calculate = ({setState, currentRound}) => {
const animateNext = () => { const animateNext = () => {
const current = round.shift(); const current = round.shift();
if (!current) return; if (!current) return;
let sold = current.amount < nachfrage ? current.amount : nachfrage; let sold = current.amount < nachfrage ? current.amount : nachfrage;
setNachfrage(nachfrage => nachfrage - sold);
let profit = sold * current.price - (current.amount * 1000 + 4000); setNachfrage(nachfrage => nachfrage - sold);
let profit = sold * current.price - (current.amount * costPerCake + costPerRound);
let currentRound = {...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};
console.log(currentRound);
setAnimatedGroups(old => [...old, currentRound]); setAnimatedGroups(old => [...old, currentRound]);
updateCapital(current.id, currentRound.newCapital); updateCapital(current.id, currentRound.newCapital);