| @ -0,0 +1,19 @@ | |||||
| import React, { Component } from 'react'; | |||||
| import RoomListItem from 'roomListItem'; | |||||
| class RoomList extends Component { | |||||
| renderRooms(roomArray) { | |||||
| return( | |||||
| <RoomListItem key = {room.name} roomName = {room.name} private = {room.passwordBool} capacity = {room.capacity} occupancy = {room.occupants} /> | |||||
| ) | |||||
| } | |||||
| render(){ | |||||
| return( | |||||
| <div> | |||||
| {this.props.roomArray.map(this.renderRooms)} | |||||
| </div> | |||||
| ) | |||||
| } | |||||
| } | |||||
| @ -0,0 +1,16 @@ | |||||
| import React from 'react'; | |||||
| export default (props) => { | |||||
| if (props.private = false){ | |||||
| const privateString = "Public" | |||||
| } else { | |||||
| const privateString = "Private" | |||||
| } | |||||
| return( | |||||
| <div> | |||||
| <h1>{props.roomName}</h1> | |||||
| <h3>`${props.occupancy}/${props.capacity}`</h3> | |||||
| <p>{privateString}</p> | |||||
| </div> | |||||
| ) | |||||
| } | |||||
| @ -1,16 +1,30 @@ | |||||
| import React, { Component } from 'react'; | import React, { Component } from 'react'; | ||||
| import ROOM_CAPACITY from '../App' | |||||
| export default class activeButton extends Component { | export default class activeButton extends Component { | ||||
| render(){ | render(){ | ||||
| if (this.props.input != ''){ | |||||
| return( | |||||
| <button>Let's play!</button> | |||||
| ) | |||||
| } else { | |||||
| return( | |||||
| <button>Enter a nickname.</button> | |||||
| ) | |||||
| switch (this.props.type) { | |||||
| case 'register': | |||||
| if(this.props.input != ''){ | |||||
| return( | |||||
| <button>Let's play!</button> | |||||
| ) | |||||
| } else { | |||||
| return( | |||||
| <button disabled>Enter a nickname to play.</button> | |||||
| ) | |||||
| } | |||||
| case 'createRoom': | |||||
| if(this.props.passInput != '' && this.props.capacityInput != '' && this.props.capacityInput <= 25 && this.props.capacityInput>=2 && this.props.capacityInput.length <= 2){ | |||||
| return( | |||||
| <button>Create Room</button> | |||||
| ) | |||||
| } else { | |||||
| return( | |||||
| <button disabled>Enter password and capacity to create a room.</button> | |||||
| ) | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| @ -0,0 +1,45 @@ | |||||
| import React, { Component } from 'react'; | |||||
| import ActiveButton from './activeButton'; | |||||
| export default class CreateRoomInput extends Component { | |||||
| constructor(props){ | |||||
| super(props); | |||||
| this.state={ | |||||
| passwordFieldValue: '', | |||||
| capacityFieldValue:'' | |||||
| } | |||||
| this.onInputChangePass = this.onInputChangePass.bind(this); | |||||
| this.onInputChangeCapacity = this.onInputChangeCapacity.bind(this); | |||||
| this.sendRoomData = this.sendRoomData.bind(this); | |||||
| } | |||||
| onInputChangePass(event) { | |||||
| this.setState({ passwordFieldValue: event.target.value }); | |||||
| } | |||||
| onInputChangeCapacity(event) { | |||||
| this.setState({ capacityFieldValue: event.target.value}); | |||||
| } | |||||
| sendRoomData(event){ | |||||
| event.preventDefault(); | |||||
| this.props.socket.emit('createRoom', {password: this.state.passwordFieldValue, capacity: this.state.capacityFieldValue}); | |||||
| this.setState({ passwordFieldValue: '', capacityFieldValue: '' }); | |||||
| } | |||||
| render(){ | |||||
| return( | |||||
| <form onSubmit={this.sendRoomData}> | |||||
| <input type="password" placeholder="Password" onChange = {this.onInputChangePass} value={this.state.passwordFieldValue} /> | |||||
| <input type='number' placeholder="Max room members" onChange = {this.onInputChangeCapacity} value={this.state.capacityFieldValue} /> | |||||
| <span> | |||||
| <ActiveButton passInput={this.state.passwordFieldValue} capacityInput={this.state.capacityFieldValue} type='createRoom' /> | |||||
| </span> | |||||
| </form> | |||||
| ) | |||||
| } | |||||
| } | |||||