team setting and postgres constraint
This commit is contained in:
@@ -5,26 +5,29 @@ const actions = require('./../actions');
|
||||
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { team, showNav } = state;
|
||||
const {
|
||||
teamSelect,
|
||||
showNav,
|
||||
ws,
|
||||
} = state;
|
||||
|
||||
function sendAccountSetTeam() {
|
||||
return ws.sendAccountSetTeam(teamSelect);
|
||||
}
|
||||
|
||||
return {
|
||||
team,
|
||||
sendAccountSetTeam,
|
||||
teamSelect,
|
||||
showNav,
|
||||
};
|
||||
},
|
||||
function receiveDispatch(dispatch) {
|
||||
function navToList() {
|
||||
dispatch(actions.setGame(null));
|
||||
dispatch(actions.setInstance(null));
|
||||
return dispatch(actions.setNav('list'));
|
||||
}
|
||||
|
||||
function setShowNav(v) {
|
||||
return dispatch(actions.setShowNav(v));
|
||||
}
|
||||
|
||||
return {
|
||||
navToList,
|
||||
setShowNav,
|
||||
};
|
||||
}
|
||||
@@ -33,20 +36,18 @@ const addState = connect(
|
||||
function TeamFooter(args) {
|
||||
const {
|
||||
showNav,
|
||||
team,
|
||||
navToList,
|
||||
teamSelect,
|
||||
sendAccountSetTeam,
|
||||
setShowNav,
|
||||
} = args;
|
||||
|
||||
if (!team) return false;
|
||||
|
||||
return (
|
||||
<footer>
|
||||
<button id="nav-btn" onClick={() => setShowNav(!showNav)} >☰</button>
|
||||
<button
|
||||
disabled={team.some(c => !c)}
|
||||
onClick={() => navToList()}>
|
||||
Confirm
|
||||
disabled={teamSelect.some(c => !c)}
|
||||
onClick={sendAccountSetTeam}>
|
||||
Set Team
|
||||
</button>
|
||||
</footer>
|
||||
);
|
||||
|
||||
@@ -8,11 +8,9 @@ const { stringSort } = require('./../utils');
|
||||
const SpawnButton = require('./spawn.button');
|
||||
const { ConstructAvatar } = require('./construct');
|
||||
|
||||
const idSort = stringSort('id');
|
||||
|
||||
const addState = connect(
|
||||
function receiveState(state) {
|
||||
const { ws, constructs, team } = state;
|
||||
const { ws, constructs, teamSelect } = state;
|
||||
|
||||
function sendConstructSpawn(name) {
|
||||
return ws.sendMtxConstructSpawn(name);
|
||||
@@ -20,27 +18,26 @@ const addState = connect(
|
||||
|
||||
return {
|
||||
constructs,
|
||||
team,
|
||||
teamSelect,
|
||||
sendConstructSpawn,
|
||||
};
|
||||
},
|
||||
|
||||
function receiveDispatch(dispatch) {
|
||||
function setTeam(constructIds) {
|
||||
localStorage.setItem('team', JSON.stringify(constructIds));
|
||||
dispatch(actions.setTeam(constructIds));
|
||||
dispatch(actions.setTeamSelect(constructIds));
|
||||
}
|
||||
|
||||
return {
|
||||
setTeam,
|
||||
};
|
||||
}
|
||||
|
||||
);
|
||||
|
||||
function Team(args) {
|
||||
const {
|
||||
constructs,
|
||||
team,
|
||||
teamSelect,
|
||||
setTeam,
|
||||
sendConstructSpawn,
|
||||
} = args;
|
||||
@@ -51,27 +48,25 @@ function Team(args) {
|
||||
// so much for dumb components
|
||||
function selectConstruct(id) {
|
||||
// remove
|
||||
const i = team.findIndex(sid => sid === id);
|
||||
const i = teamSelect.findIndex(sid => sid === id);
|
||||
if (i > -1) {
|
||||
team[i] = null;
|
||||
return setTeam(team);
|
||||
teamSelect[i] = null;
|
||||
return setTeam(teamSelect);
|
||||
}
|
||||
|
||||
// window insert
|
||||
const insert = team.findIndex(j => j === null);
|
||||
const insert = teamSelect.findIndex(j => j === null);
|
||||
if (insert === -1) return setTeam([id, null, null]);
|
||||
team[insert] = id;
|
||||
return setTeam(team);
|
||||
teamSelect[insert] = id;
|
||||
return setTeam(teamSelect);
|
||||
}
|
||||
|
||||
const constructPanels = constructs.map(construct => {
|
||||
const colour = team.indexOf(construct.id);
|
||||
const colour = teamSelect.indexOf(construct.id);
|
||||
const selected = colour > -1;
|
||||
|
||||
const borderColour = selected ? COLOURS[colour] : '#000000';
|
||||
|
||||
|
||||
// <button disabled={true} >↻</button>
|
||||
return (
|
||||
<div
|
||||
key={construct.id}
|
||||
|
||||
Reference in New Issue
Block a user