From 88408b75430f64de5e67ac15ae5d9bbada439e27 Mon Sep 17 00:00:00 2001 From: Jonny Date: Tue, 16 Apr 2019 13:40:12 +0200 Subject: [PATCH] Implement drag and drop for teams in groups --- js/components/EditableStringList.js | 43 +++++++++++++++++++++++++++-- 1 file changed, 41 insertions(+), 2 deletions(-) diff --git a/js/components/EditableStringList.js b/js/components/EditableStringList.js index ac83afd..b9027e4 100644 --- a/js/components/EditableStringList.js +++ b/js/components/EditableStringList.js @@ -13,6 +13,7 @@ import { import '../../static/css/editablestringlist.css'; export default class EditableStringList extends React.Component { + constructor(props) { super(props); this.state = { @@ -22,6 +23,7 @@ export default class EditableStringList extends React.Component { }; this.add = this.add.bind(this); this.remove = this.remove.bind(this); + this.onGroupSwitch = this.onGroupSwitch.bind(this); } add(text) { @@ -125,6 +127,10 @@ export default class EditableStringList extends React.Component { this.props.onGroupsChange(this.state.groups); } + onGroupSwitch(src, dest) { + console.log('Switched src (' + JSON.stringify(src) + ') to dest (' + JSON.stringify(dest) + ')' ); + } + render() { if(this.props.groupSize !== this.state.groupSize) { this.resizeGroups(this.props.groupSize); @@ -179,8 +185,15 @@ class GroupView extends React.Component { Group {groupindex + 1} - {group.map((team) => ( - + {group.map((team, teamindex) => ( +
this.onDragStart(e, groupindex,teamindex)} + onDragOver={(e) => this.onDragOver(e)} + onDrop={(e) => this.onDrop(e, groupindex, teamindex)}> + + + +
))}
@@ -188,6 +201,32 @@ class GroupView extends React.Component { ); } + + onDragStart(e, group, team) { + e.dataTransfer.setData( + 'text/plain', + JSON.stringify({ + group: group, + team: team + }) + ); + } + + onDragOver(e) { + e.preventDefault(); + } + + onDrop(e, group, team) { + e.preventDefault(); + + let src = JSON.parse(e.dataTransfer.getData('text')); + let dest = { + group: group, + team: team + }; + + this.props.onGroupSwitched(src, dest); + } } class StringInput extends React.Component {