Updated the Calculate.jsx state
This commit is contained in:
parent
b1ee8b2213
commit
06f1c2eae8
@ -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);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user