From 2b80d6ae4bff46c11c2d2656e811d53b072fdd60 Mon Sep 17 00:00:00 2001 From: Chris Karle Date: Sun, 31 May 2020 23:00:35 -0400 Subject: [PATCH] TableList Add new passwordModal functionality: if clicked room card needs a password, hang the joinInfo on local state and open a ComposedModal with single textInput to take password. Modal Save adds the entered password to the JoinInfo and calls joinTable with it. --- assets/components/TableList.js | 77 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 74 insertions(+), 3 deletions(-) diff --git a/assets/components/TableList.js b/assets/components/TableList.js index cab4c29..9c3f591 100644 --- a/assets/components/TableList.js +++ b/assets/components/TableList.js @@ -1,10 +1,19 @@ import React from 'react'; import PropTypes from 'prop-types'; -import { ClickableTile, Button, ModalWrapper, TextInput, Checkbox } from 'carbon-components-react'; +import { ClickableTile, Button, ModalWrapper, TextInput, Checkbox, ComposedModal, + ModalHeader, ModalBody, ModalFooter } from 'carbon-components-react'; import {Renew16, Locked16} from '@carbon/icons-react'; export default class TableList extends React.Component { + constructor(props) { + super(props); + this.state = { + pwdOpen: false, + joinInfo: null + }; + } + conflictHandler = (tableName) => { const {playerName} = this.props; alert('The "' + tableName + '" table already has a player named ' + playerName @@ -18,7 +27,14 @@ export default class TableList extends React.Component { table: tableName, player_name: playerName }; - this.props.joinTable(joinInfo); + if (!hasPwd) { + this.props.joinTable(joinInfo); + } else { + this.setState({ + joinInfo: joinInfo, + pwdOpen: true + }) + } } handleCreate = () => { @@ -43,7 +59,27 @@ export default class TableList extends React.Component { handleRefresh = () => { this.refreshButton.blur(); this.props.refresh(); - } + }; + + handleModalClose = () => { + console.log('modal close'); + this.pmPwd.value=''; + this.setState({ + pwdOpen: false + }); + }; + + handleModalSave = () => { + const {joinInfo} = this.state; + const pwd = this.pmPwd.value; + console.log('modal save, pwd=', pwd); + joinInfo.password = pwd; + this.props.joinTable(joinInfo); + this.pmPwd.value=''; + this.setState({ + pwdOpen: false + }); + }; renderCards = () => { const {tables, playerName} = this.props; @@ -96,12 +132,47 @@ export default class TableList extends React.Component { return retVal; } + renderPasswordModal = () => { + const {pwdOpen} = this.state; + return ( + + + + {this.pmPwd = input;}} + /> + + + + ); + } + render () { const {tables} = this.props; const showCards = tables.length > 0; const cards = this.renderCards(); + const passwordModal = this.renderPasswordModal(); return (
+ {passwordModal}
Click a table to join it... or
-- libgit2 1.1.1