bug resolution

This commit is contained in:
Lukian LEIZOUR 2024-06-05 15:45:47 +02:00
parent 62b67b94b0
commit 5971eea3cb
2 changed files with 11 additions and 6 deletions

View file

@ -2,8 +2,8 @@ import { useEffect, useState } from 'react';
import { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import axios from 'axios';
export default function HelpButton({ gameid, helpingprop, token }) {
const [helping, setHelping] = useState(helpingprop);
export default function HelpButton({ gameid, token, user }) {
const [helping, setHelping] = useState();
function addHelper() {
axios.post("https://leizour.fr/api/v1/games/addHelper", { token, gameid })
@ -18,7 +18,6 @@ export default function HelpButton({ gameid, helpingprop, token }) {
}
function handleClick(event) {
console.log("helping:", helping)
if (helping) {
removeHelper();
} else {
@ -27,8 +26,14 @@ export default function HelpButton({ gameid, helpingprop, token }) {
}
useEffect(() => {
setHelping(helpingprop);
}, [helpingprop]);
async function fetchGame() {
const response = await axios.post("https://leizour.fr/api/v1/games/getGame", { token, gameid })
.catch((error) => console.error("Error getting game"));
setHelping(JSON.parse(response.data.helpers).includes(user.username));
}
fetchGame();
}, [gameid]);
useEffect(() => {
if (helping) {

View file

@ -124,7 +124,7 @@ export default function Home() {
<p className='helper'>{helper}</p>
))))}
</div>
<HelpButton gameid={game.id} helpingprop={JSON.parse(game.helpers).includes(user.username)} token={token} />
<HelpButton gameid={game.id} helpingprop={JSON.parse(game.helpers).includes(user.username)} user={user} token={token} />
</div>
</div>
</div>