-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
friend page finie, stat + historique en cours
- Loading branch information
Nicolas Jaros
committed
Apr 21, 2023
1 parent
84cb6e8
commit b8e3c7b
Showing
14 changed files
with
218 additions
and
111 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
71 changes: 71 additions & 0 deletions
71
front/react_project/src/components/ProfileModule/MatchHistory.tsx
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
import { useContext, useEffect, useState } from "react"; | ||
import { SocketContext } from "../context"; | ||
import { JwtPayload } from "jsonwebtoken"; | ||
import { accountService } from "../../services/account.service"; | ||
|
||
export default function MatchHistory(props: {userId: string}) { | ||
const {socketGame} = useContext(SocketContext); | ||
const [history, setHistory] = useState<{ | ||
matchId: string, | ||
winnerId: string, | ||
winnerLogin: string, | ||
scoreWinner: number, | ||
loserId: string, | ||
loserLogin: string, | ||
scoreLoser: number}[]>([]); | ||
const [matchWon, setMatchWon] = useState<number>(0); | ||
const [matchLost, setMatchLost] = useState<number>(0); | ||
|
||
|
||
useEffect(() => { | ||
socketGame.emit("matchHistory", {userId: props.userId}); | ||
}, [props.userId]); | ||
|
||
useEffect(() => { | ||
socketGame.on("matchHistory", (data: { | ||
matchId: string, | ||
winnerId: string, | ||
winnerLogin: string, | ||
scoreWinner: number, | ||
loserId: string, | ||
loserLogin: string, | ||
scoreLoser: number}[] ) => { | ||
let win = 0; | ||
let loose = 0; | ||
data.forEach((elt) => { | ||
if (elt.winnerId == props.userId) | ||
++win; | ||
else | ||
++loose; | ||
}); | ||
console.log("win: ", win, ", loose: ", loose); | ||
setMatchWon(win); | ||
setMatchLost(loose); | ||
setHistory(data); | ||
}) | ||
}, []) | ||
|
||
return ( | ||
<div id="score"> | ||
<div id="stats"> | ||
<h2>Statistics</h2> | ||
<h3>total win = {matchWon}</h3> | ||
<h3>total lost = {matchLost}</h3> | ||
<h3>ratio = {matchLost == 0 ? (matchWon == 0 ? "NaN" : "full perfect") : matchWon / matchLost}</h3> | ||
</div> | ||
<div id="history"> | ||
<h2>Match history</h2> | ||
<ul id="matchList"> | ||
{history.map((elt) => ( | ||
<li id="historyElement" key={elt.matchId}> | ||
<span id="winnerName" className="name">{elt.winnerLogin}</span> | ||
<span id="winnerScore">{elt.scoreWinner}</span> | ||
<span id="loserName" className="name">{elt.loserLogin}</span> | ||
<span id="loserScore">{elt.scoreLoser}</span> | ||
</li> | ||
))} | ||
</ul> | ||
</div> | ||
</div> | ||
) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.