bug resolution
This commit is contained in:
parent
62b67b94b0
commit
5971eea3cb
2 changed files with 11 additions and 6 deletions
|
@ -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) {
|
||||
|
|
|
@ -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>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue