From 8aad4d614d7c94370b9295f9e561bb89bb318c7b Mon Sep 17 00:00:00 2001 From: Jonny Date: Tue, 16 Apr 2019 10:51:48 +0200 Subject: [PATCH] Make groups visible and add the teams to the groups --- js/components/EditableStringList.js | 86 +++++++++++++++++++++++------ pages/create.js | 1 + 2 files changed, 71 insertions(+), 16 deletions(-) diff --git a/js/components/EditableStringList.js b/js/components/EditableStringList.js index 2f0e84f..24b33de 100644 --- a/js/components/EditableStringList.js +++ b/js/components/EditableStringList.js @@ -19,12 +19,26 @@ export default class EditableStringList extends React.Component { } add(text) { - if (text === '' || this.props.teams.includes(text)) { + if (text === '' || this.state.teams.includes(text)) { return false; } - this.props.teams.push(text); - this.setState({teams: this.state.teams}); + this.state.teams.push(text); + + var lastGroup = this.state.groups[this.state.groups.length - 1]; + if(lastGroup === undefined || lastGroup.length === this.props.groupSize) { + this.state.groups[this.state.groups.length] = []; + } + lastGroup = this.state.groups[this.state.groups.length - 1]; + lastGroup[lastGroup.length] = text; + + this.setState({ + teams: this.state.teams, + groups: this.state.groups + }); + this.props.onTeamsChange(this.state.teams); + this.props.onGroupsChange(this.state.groups); + return true; } @@ -35,24 +49,64 @@ export default class EditableStringList extends React.Component { } render() { - if ((typeof this.state.teams !== 'undefined') && this.state.teams.length > 0) { - return ( -
- - {this.state.teams.map((text) => )} -
- ); + if(this.props.groupPhaseEnabled) { + if ((typeof this.state.teams !== 'undefined') && this.state.teams.length > 0) { + return ( +
+ + +
+ ); + } else { + return ( +
+ + {this.props.groupPlaceHolder} +
+ ); + } } else { - return ( -
- - {this.props.teamPlaceholder} -
- ); + if ((typeof this.state.teams !== 'undefined') && this.state.teams.length > 0) { + return ( +
+ + {this.state.teams.map((text) => )} +
+ ); + } else { + return ( +
+ + {this.props.teamPlaceholder} +
+ ); + } } } } +class GroupView extends React.Component { + + constructor(props) { + super(props); + } + + render() { + return ( +
+ {this.props.groups.map((group, groupindex) => ( +
+ Group {groupindex + 1} + {group.map((team, teamindex) => ( +
{team}
+ ))} +
+ ))} +
+ ); + } +} + class StringInput extends React.Component { constructor(props) { super(props); diff --git a/pages/create.js b/pages/create.js index 5c7f6fc..00417f3 100644 --- a/pages/create.js +++ b/pages/create.js @@ -114,6 +114,7 @@ class CreateTournamentForm extends React.Component { }; this.handleGroupPhaseEnabledInput = this.handleGroupPhaseEnabledInput.bind(this); this.teamListUpdate = this.teamListUpdate.bind(this); + this.groupListUpdate = this.groupListUpdate.bind(this); this.handleGroupSizeInput = this.handleGroupSizeInput.bind(this); this.handleGroupAdvanceInput = this.handleGroupAdvanceInput.bind(this);