added handler for ready button
This commit is contained in:
@@ -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;
|
||||
|
||||
Reference in New Issue
Block a user