1
0

Add spinner

Signed-off-by: James Ketrenos <james_eikona@ketrenos.com>
This commit is contained in:
James Ketrenos 2022-02-28 00:00:18 -08:00
parent 644fea6ba8
commit 091d20e53d

View File

@ -17,6 +17,8 @@ import Resource from './Resource.js';
import ViewCard from './ViewCard.js'; import ViewCard from './ViewCard.js';
import Winner from './Winner.js'; import Winner from './Winner.js';
import ChooseCard from './ChooseCard.js'; import ChooseCard from './ChooseCard.js';
import { CircularProgress } from "@material-ui/core";
import 'moment-timezone';
/* Start of withRouter polyfill */ /* Start of withRouter polyfill */
// https://reactrouter.com/docs/en/v6/faq#what-happened-to-withrouter-i-need-it // https://reactrouter.com/docs/en/v6/faq#what-happened-to-withrouter-i-need-it
@ -218,7 +220,7 @@ const Chat = ({ table }) => {
} }
const name = table.game ? table.game.name : "Why no game?"; const name = table.game ? table.game.name : "Why no game?";
const startTime = table.game ? table.game.startTime : Date.now(); const elapsed = table.game ? (table.game.timestamp - table.game.startTime) : undefined;
return ( return (
<Paper className="Chat"> <Paper className="Chat">
<List className="ChatList" id="ChatList" onScroll={chatScroll}> <List className="ChatList" id="ChatList" onScroll={chatScroll}>
@ -228,7 +230,7 @@ const Chat = ({ table }) => {
disabled={!name} disabled={!name}
onChange={chatInput} onChange={chatInput}
onKeyPress={chatKeyPress} onKeyPress={chatKeyPress}
label={(<Moment format="h:mm:ss">{Date.now()-startTime}</Moment>)} variant="outlined"/> label={elapsed && <Moment tz={"Etc/GMT"} format="h:mm:ss" durationFromNow interval={1000} date={table.game.startTime}></Moment>} variant="outlined"/>
</Paper> </Paper>
); );
} }
@ -523,7 +525,8 @@ class Table extends React.Component {
error: "", error: "",
signature: "", signature: "",
buildActive: false, buildActive: false,
cardActive: undefined cardActive: undefined,
loading: 0
}; };
this.componentDidMount = this.componentDidMount.bind(this); this.componentDidMount = this.componentDidMount.bind(this);
this.updateDimensions = this.updateDimensions.bind(this); this.updateDimensions = this.updateDimensions.bind(this);
@ -585,6 +588,8 @@ class Table extends React.Component {
value = ''; value = '';
} }
this.setState({ loading: this.state.loading + 1 });
return window.fetch(`${base}/api/v1/games/${this.state.game.id}/${action}/${value}`, { return window.fetch(`${base}/api/v1/games/${this.state.game.id}/${action}/${value}`, {
method: "PUT", method: "PUT",
cache: 'no-cache', cache: 'no-cache',
@ -607,6 +612,7 @@ class Table extends React.Component {
console.error(error); console.error(error);
this.setState({error: error.message}); this.setState({error: error.message});
}).then(() => { }).then(() => {
this.setState({ loading: this.state.loading - 1 });
this.resetGameLoad(); this.resetGameLoad();
}); });
} }
@ -685,6 +691,7 @@ class Table extends React.Component {
return; return;
} }
this.setState({ loading: this.state.loading + 1 });
return window.fetch(`${base}/api/v1/games/${this.state.game.id}`, { return window.fetch(`${base}/api/v1/games/${this.state.game.id}`, {
method: "GET", method: "GET",
cache: 'no-cache', cache: 'no-cache',
@ -707,6 +714,7 @@ class Table extends React.Component {
console.error(error); console.error(error);
this.setState({error: error.message}); this.setState({error: error.message});
}).then(() => { }).then(() => {
this.setState({ loading: this.state.loading - 1 });
this.resetGameLoad(); this.resetGameLoad();
}); });
} }
@ -725,6 +733,7 @@ class Table extends React.Component {
this.loadTimer = null; this.loadTimer = null;
} }
this.setState({ loading: this.state.loading + 1 });
return window.fetch(`${base}/api/v1/games/${this.state.game.id}/state/${state}`, { return window.fetch(`${base}/api/v1/games/${this.state.game.id}/state/${state}`, {
method: "PUT", method: "PUT",
cache: 'no-cache', cache: 'no-cache',
@ -746,6 +755,7 @@ class Table extends React.Component {
console.error(error); console.error(error);
this.setState({error: error.message}); this.setState({error: error.message});
}).then(() => { }).then(() => {
this.setState({ loading: this.state.loading + 1 });
this.resetGameLoad(); this.resetGameLoad();
return this.game.state; return this.game.state;
}); });
@ -952,6 +962,7 @@ class Table extends React.Component {
params.method = "POST"; params.method = "POST";
} }
this.setState({ loading: this.state.loading + 1 });
window.fetch(params.url, { window.fetch(params.url, {
method: params.method, method: params.method,
cache: 'no-cache', cache: 'no-cache',
@ -1000,6 +1011,7 @@ class Table extends React.Component {
console.error(error); console.error(error);
this.setState({error: error.message}); this.setState({error: error.message});
}).then(() => { }).then(() => {
this.setState({ loading: this.state.loading - 1 });
this.resetGameLoad(); this.resetGameLoad();
}); });
@ -1060,6 +1072,9 @@ class Table extends React.Component {
return ( return (
<div className="Table"> <div className="Table">
{ this.state.loading > 0 &&
<CircularProgress className='Loading'/>
}
<div style={{display: "inline-flex", flex: 1, flexDirection: "column"}}> <div style={{display: "inline-flex", flex: 1, flexDirection: "column"}}>
<Board table={this} game={game}/> <Board table={this} game={game}/>