From 46ed52f21d3ff6025f964549220b305967367fc0 Mon Sep 17 00:00:00 2001 From: Mathias Wagner Date: Wed, 22 Nov 2023 12:14:07 +0100 Subject: [PATCH] Integrated the round history in the End.jsx --- client/src/pages/End/End.jsx | 112 +++++++++++++++++++++++++++-------- 1 file changed, 87 insertions(+), 25 deletions(-) diff --git a/client/src/pages/End/End.jsx b/client/src/pages/End/End.jsx index 6cf165b..1f62504 100644 --- a/client/src/pages/End/End.jsx +++ b/client/src/pages/End/End.jsx @@ -1,11 +1,13 @@ import "./styles.sass"; -import {useContext, useEffect} from "react"; +import {useContext, useEffect, useState} from "react"; import {socket} from "@/common/utils/socket.js"; import {GroupContext} from "@/common/contexts/GroupContext.jsx"; import Sound from "react-sound"; import ThemeSound from "@/common/sounds/end.mp3"; import {MusicContext} from "@/common/contexts/MusicContext.jsx"; import {Navigate} from "react-router"; +import Button from "@/common/components/Button"; +import {faArrowLeft, faArrowRight} from "@fortawesome/free-solid-svg-icons"; const localeOptions = { style: "decimal", @@ -16,47 +18,107 @@ const localeOptions = { export const End = () => { - const {groups, allGroups} = useContext(GroupContext); + const {groups, allGroups, roundHistory} = useContext(GroupContext); const {musicEnabled} = useContext(MusicContext); + const [roundShown, setRoundShown] = useState(roundHistory.length + 1); + useEffect(() => { socket.disconnect(); socket.connect(); }, []); + const nextRound = () => { + if (roundShown === roundHistory.length + 1) return; + setRoundShown(round => round + 1); + } + + const prevRound = () => { + if (roundShown === 1) return; + setRoundShown(round => round - 1); + } + if (groups.length === 0 && allGroups.length === 0) return ; return (
- {[...groups, ...allGroups].sort((a, b) => b.capital - a.capital).map(group => ( -
-
-

Unternehmen

-

{group.name}

-
-
-

Startkapital

-

25.000 €

-
+
+
+

{roundShown === roundHistory.length + 1 ? "Endergebnis" : "Runde " + roundShown}

-
-

Gewinn/Verlust

- {group.capital - 25000 > 0 && -

+ {(group.capital - 25000)?.toLocaleString("de-DE", localeOptions)} €

} - {group.capital - 25000 < 0 && -

- {(group.capital - 25000)?.toLocaleString("de-DE", localeOptions)} €

} - {group.capital - 25000 === 0 &&

0 €

} -
- -
-

Firmenwert

-

{group.capital < 5000 ? "Pleite" : group.capital?.toLocaleString("de-DE", localeOptions) + " €"}

+
+ {roundShown !== 1 &&
- ))} + + {roundShown !== roundHistory.length + 1 && roundHistory[roundShown - 1].sort((a, b) => b.capital - a.capital).map(r => ( +
+
+

Unternehmen

+

{r.name}

+
+ +
+

Absatzpreis

+

{r.price?.toLocaleString("de-DE", localeOptions)} €

+
+ +
+

Menge

+

{r.amount} Kisten

+
+ +
+

Verkauft

+

{r.sold} Kisten

+
+ +
+

Kapital + {r.profit > 0 && + {r.profit?.toLocaleString("de-DE", localeOptions)} €} + {r.profit < 0 && - {r.profit?.toLocaleString("de-DE", localeOptions)} €} + {r.profit === 0 && (Unverändert)} +

+

{r.newCapital?.toLocaleString("de-DE", localeOptions)} €

+
+
+ ))} + + + {roundShown === roundHistory.length + 1 && [...groups, ...allGroups].sort((a, b) => b.capital - a.capital).map(group => ( +
+
+

Unternehmen

+

{group.name}

+
+ +
+

Startkapital

+

25.000 €

+
+ +
+

Gewinn/Verlust

+ {group.capital - 25000 > 0 && +

+ {(group.capital - 25000)?.toLocaleString("de-DE", localeOptions)} €

} + {group.capital - 25000 < 0 && +

- {(group.capital - 25000)?.toLocaleString("de-DE", localeOptions)} €

} + {group.capital - 25000 === 0 &&

0 €

} +
+ +
+

Firmenwert

+

{group.capital < 5000 ? "Pleite" : group.capital?.toLocaleString("de-DE", localeOptions) + " €"}

+
+
+ ))} +
); } \ No newline at end of file