added changing color in navbar if ready

This commit is contained in:
Wenszel
2021-03-20 20:49:47 +01:00
parent 0844f23c4e
commit e32b46556c
9 changed files with 94 additions and 57 deletions
+2 -2
View File
@@ -14,7 +14,7 @@ function App() {
const [redirect, setRedirect] = useState()
useEffect(() => {
axios.get('http://localhost:3000', {
axios.get('http://localhost:3000/player', {
withCredentials:true,
mode: 'cors'
})
@@ -33,7 +33,7 @@ function App() {
const idCallback = (id)=>{
setId(id);
axios.get('http://localhost:3000', {
axios.get('http://localhost:3000/player/', {
withCredentials:true,
mode: 'cors',
headers: { "Content-Type": "application/json" },
+6 -4
View File
@@ -6,9 +6,8 @@ import axios from 'axios';
const Navbar = () => {
const [players, setPlayers] = useState([]);
useEffect(()=>{
//fetching players data
//fetching players data to display them in navbar
const fetchData = () => {
axios.get('http://localhost:3000/room/',{
withCredentials:true,
mode: 'cors',
@@ -16,11 +15,14 @@ const Navbar = () => {
while(response.data.players.length !== 4){
response.data.players.push({
name: "...",
color: "grey"
})
}
setPlayers(response.data.players);
})
}
useEffect(()=>{
//sending ajax every 3 sec
setInterval(fetchData, 3000);
},[]);
return(
@@ -1,9 +1,9 @@
import React from 'react';
import './NameContainer.css'
const NameContainer = ( {player} ) => {
return (
<div className="name-container" style={{backgroundColor: player.color}}>
<div className="name-container"
style={ player.ready ? { backgroundColor: player.color} : { backgroundColor: 'grey'} }>
{player.name}
</div>
)
@@ -12,9 +12,9 @@ const ReadyButton = () => {
}
return(
<div>
<label>Ready: </label>
<div className="ready-container">
<Switch onClick={handleCheckboxChange} checked={checked}/>
<label>{checked ? 'I want to play' : 'Im waiting' }</label>
</div>
)