added handler for ready button

This commit is contained in:
Wenszel
2022-05-30 09:52:42 +02:00
parent 159b96a678
commit 5eea80b804
4 changed files with 58 additions and 70 deletions
+1
View File
@@ -38,6 +38,7 @@ const Gameboard = () => {
useEffect(() => {
socket.on('room:data', data => {
data = JSON.parse(data);
//console.log(data);
// Filling navbar with empty player nick container
while (data.players.length !== 4) {
data.players.push({ name: '...' });
@@ -1,23 +1,22 @@
import React, { useState } from 'react';
import React, { useState, useContext } from 'react';
import { SocketContext } from '../../App';
import Switch from '@material-ui/core/Switch';
import axios from 'axios';
const ReadyButton = () => {
const [checked, setChecked] = useState(false)
const socket = useContext(SocketContext);
const [checked, setChecked] = useState(false);
const handleCheckboxChange = () => {
axios.post('/player/ready',{},{withCredentials: true});
socket.emit('player:ready');
setChecked(!checked);
}
return(
<div className="ready-container">
<Switch onClick={handleCheckboxChange} checked={checked}/>
<label>{checked ? 'I want to play' : 'Im waiting' }</label>
</div>
)
};
}
return (
<div className='ready-container'>
<Switch onClick={handleCheckboxChange} checked={checked} />
<label>{checked ? 'I want to play' : 'Im waiting'}</label>
</div>
);
};
export default ReadyButton;
export default ReadyButton;