Skip to content

Commit 57e09ac

Browse files
authored
Merge pull request #141 from YuStudy-Inc/finalfixes
fixed the result page
2 parents b0f8d32 + 2a8dd38 commit 57e09ac

File tree

4 files changed

+35
-42
lines changed

4 files changed

+35
-42
lines changed

Frontend/src/Components/Results/ResultCard.jsx

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import "../../Styles/Components/Results/ResultsCard.css"
22

3-
const ResultCard = ({ didWin, coins, monsters, xp, lvl }) => {
3+
const ResultCard = ({ didWin, coins, monsters }) => {
44
return (
55
<>
66
<div className="results-card-container">
@@ -11,16 +11,6 @@ const ResultCard = ({ didWin, coins, monsters, xp, lvl }) => {
1111
<p className="right-results">{coins}</p>
1212
<p className="left-results">Monsters Slain</p>
1313
<p className="right-results">{monsters}</p>
14-
<p className="left-results">XP Received</p>
15-
<p className="right-results">{xp}</p>
16-
</div>
17-
<div className="progress-bar">
18-
<div className="full-bar">
19-
<div className="actual-bar"></div>
20-
</div>
21-
<div className="level">
22-
<h1>lv. {lvl}</h1>
23-
</div>
2414
</div>
2515
</div>
2616
</div>

Frontend/src/Pages/Results/Results.jsx

Lines changed: 31 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,12 @@
11
import "../../Styles/Pages/Results/Results.css"
22
import { Podium, ResultCard } from "../../Components/Components"
3+
import { useState, useEffect } from "react"
34
import { useNavigate } from "react-router-dom"
45

5-
const Results = ({didWin, }) => {
6+
const URI = import.meta.env.VITE_APP_URI
7+
const userId = JSON.parse(localStorage.getItem('id'));
8+
9+
const Results = () => {
610
const win = "You beat the Quiz!"
711
const lose = "Better luck next time..."
812
const monstersSlain = localStorage.getItem('results') || 0;
@@ -11,6 +15,31 @@ const Results = ({didWin, }) => {
1115
navigate('/home')
1216
}
1317
console.log("Monsters slain", monstersSlain)
18+
const [totalCoins, setTotalCoins] = useState(0)
19+
20+
useEffect(() => {
21+
const coinsEarned = monstersSlain * 3
22+
setTotalCoins(coinsEarned)
23+
24+
const updateCoins = async () => {
25+
try {
26+
const response = await axios.put(`${URI}users/updateCoins/${userId}`, {
27+
coins: coinsEarned,
28+
},
29+
{
30+
withCredentials: true
31+
})
32+
if (response.status === 200) {
33+
console.log("Coins updated successfully")
34+
}
35+
} catch (error) {
36+
console.error("Failed to update coins:", error)
37+
}
38+
}
39+
40+
if (coinsEarned > 0) updateCoins()
41+
}, [monstersSlain])
42+
1443
return(
1544
<>
1645
<div className="results-container">
@@ -23,7 +52,7 @@ const Results = ({didWin, }) => {
2352
<Podium />
2453
</div>
2554
<div className="container-for-result-card">
26-
<ResultCard didWin={true} coins={"27"} monsters={monstersSlain} xp={"87"} lvl={"9"}/>
55+
<ResultCard didWin={true} coins={totalCoins} monsters={monstersSlain}/>
2756
</div>
2857
</div>
2958
</div>

Frontend/src/Styles/Components/Results/ResultsCard.css

Lines changed: 0 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -40,31 +40,5 @@
4040
font-size: 1.4rem;
4141
}
4242

43-
.progress-bar {
44-
height: auto;
45-
width: 100%;
46-
display: flex;
47-
flex-direction: column;
48-
gap: 5px;
49-
}
50-
51-
.full-bar {
52-
width: 100%;
53-
height: 20px;
54-
background-color: var(--black);
55-
border-radius: 20px;
56-
margin-top: 10%;
57-
}
58-
59-
.actual-bar {
60-
z-index: 10;
61-
position: absolute;
62-
/* pass it from the game */
63-
/* this is scuffed rn, 100% width goes outside the full bar for some reason */
64-
height: 20px;
65-
border-radius: 20px;
66-
width: 10%;
67-
background-color: var(--light-green) !important;
68-
}
6943

7044

Frontend/src/Styles/Pages/Results/Results.css

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@
3636
width: 100%;
3737
display: flex;
3838
justify-content: space-between;
39-
align-items: end;
39+
align-items: center;
4040
}
4141

4242
.container-for-podium-results-page {
@@ -48,8 +48,8 @@
4848
}
4949

5050
.container-for-result-card {
51-
height: 80%;
52-
width: 55%;
51+
height: 40%;
52+
width: 50%;
5353
display: flex;
5454
align-items: center;
5555
margin-bottom: 5%;

0 commit comments

Comments
 (0)