Moving currentPlayer in to one place.
This commit is contained in:
@@ -1456,9 +1456,7 @@ class Moving extends React.Component {
|
||||
} else {
|
||||
buttons = (<Button onClick={() => this.skip()}>Skip</Button>);
|
||||
}
|
||||
const currentPlayer = this.props.player.name === this.props.game.currentPlayer ?
|
||||
this.props.player : this.props.game.otherPlayers
|
||||
.find(p => p.player.name === this.props.game.currentPlayer).player;
|
||||
const { currentPlayer } = this.props;
|
||||
return (
|
||||
<Row>
|
||||
<Col width={'12'}>
|
||||
@@ -1481,10 +1479,7 @@ class Moving extends React.Component {
|
||||
class Action extends React.Component {
|
||||
render() {
|
||||
let view, buttons;
|
||||
const currentPlayer = (this.props.player.name === this.props.game.currentPlayer ||
|
||||
this.props.game.currentPlayer === '') ?
|
||||
this.props.player : this.props.game.otherPlayers
|
||||
.find(p => p.player.name === this.props.game.currentPlayer).player;
|
||||
const { currentPlayer } = this.props;
|
||||
switch (this.props.ui.action) {
|
||||
case 'otb':
|
||||
if (this.props.player.name === this.props.game.currentPlayer) {
|
||||
@@ -1884,7 +1879,8 @@ class BoardApp extends React.Component {
|
||||
this.state = {
|
||||
screen: SCREENS.summary,
|
||||
card: props.ui.card,
|
||||
timerId: false
|
||||
timerId: false,
|
||||
currentPlayer: this.props.player
|
||||
};
|
||||
this.myRef = React.createRef();
|
||||
this.actionRef = React.createRef();
|
||||
@@ -1906,7 +1902,7 @@ class BoardApp extends React.Component {
|
||||
this.setState({ card });
|
||||
}
|
||||
|
||||
componentDidUpdate() {
|
||||
componentDidUpdate(prevProps) {
|
||||
if (this.state.card.type === 'no-card' &&
|
||||
this.props.ui.cards.length > 0) {
|
||||
this.setState({ card: this.props.ui.cards[0] });
|
||||
@@ -1925,9 +1921,20 @@ class BoardApp extends React.Component {
|
||||
this.actionShowing()) {
|
||||
this.props.alertHandled(this.props.ui.unhandledAlert.id);
|
||||
}
|
||||
|
||||
if (prevProps.game.currentPlayer !== this.props.game.currentPlayer) {
|
||||
const currentPlayer = this.props.player.name === this.props.game.currentPlayer ?
|
||||
this.props.player : this.props.game.otherPlayers
|
||||
.find(p => p.player.name === this.props.game.currentPlayer).player;
|
||||
this.setState({ currentPlayer });
|
||||
}
|
||||
}
|
||||
|
||||
componentDidMount() {
|
||||
const currentPlayer = this.props.player.name === this.props.game.currentPlayer ?
|
||||
this.props.player : this.props.game.otherPlayers
|
||||
.find(p => p.player.name === this.props.game.currentPlayer).player;
|
||||
this.setState({ currentPlayer });
|
||||
// const midColHeight = (window.innerHeight -
|
||||
// (document.getElementsByClassName('flex-row')[0].offsetHeight * 2)) + 'px';
|
||||
// const midCols = document.getElementsByClassName('mid-col');
|
||||
@@ -2076,6 +2083,7 @@ class BoardApp extends React.Component {
|
||||
}
|
||||
const actionComponent = (
|
||||
<Action
|
||||
currentPlayer={this.state.currentPlayer}
|
||||
timerId={this.state.timerId}
|
||||
setTimerId={this.setTimerId}
|
||||
forwardRef={x => this.actionRef = x}
|
||||
|
||||
Reference in New Issue
Block a user