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 { FontAwesomeIcon } from '@fortawesome/react-fontawesome'
import axios from 'axios'; import axios from 'axios';
export default function HelpButton({ gameid, helpingprop, token }) { export default function HelpButton({ gameid, token, user }) {
const [helping, setHelping] = useState(helpingprop); const [helping, setHelping] = useState();
function addHelper() { function addHelper() {
axios.post("https://leizour.fr/api/v1/games/addHelper", { token, gameid }) 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) { function handleClick(event) {
console.log("helping:", helping)
if (helping) { if (helping) {
removeHelper(); removeHelper();
} else { } else {
@ -27,8 +26,14 @@ export default function HelpButton({ gameid, helpingprop, token }) {
} }
useEffect(() => { useEffect(() => {
setHelping(helpingprop); async function fetchGame() {
}, [helpingprop]); 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(() => { useEffect(() => {
if (helping) { if (helping) {

View file

@ -124,7 +124,7 @@ export default function Home() {
<p className='helper'>{helper}</p> <p className='helper'>{helper}</p>
))))} ))))}
</div> </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> </div>
</div> </div>