Disable buttons during processing

This commit is contained in:
2021-09-12 22:55:34 +01:00
parent f596a7a8aa
commit d15be15a81
4 changed files with 32 additions and 6 deletions

View File

@@ -65,6 +65,7 @@ export default function ClassicTestStart(props) {
icon={<ArrowForwardRoundedIcon />} icon={<ArrowForwardRoundedIcon />}
className="button--round continue-button" className="button--round continue-button"
loading={props.loading} loading={props.loading}
disabled={props.disabled}
></Button> ></Button>
<Button <Button

View File

@@ -65,6 +65,7 @@ export default function LivesTestStart(props) {
icon={<ArrowForwardRoundedIcon />} icon={<ArrowForwardRoundedIcon />}
className="button--round continue-button" className="button--round continue-button"
loading={props.loading} loading={props.loading}
disabled={props.disabled}
></Button> ></Button>
<Button <Button

View File

@@ -67,6 +67,7 @@ export default withRouter(class LoggedInHome extends React.Component {
sliderValue: 1, sliderValue: 1,
switchLanguage: false, switchLanguage: false,
totalTestQuestions: 1, totalTestQuestions: 1,
pendingDeletions: {},
}; };
let isMounted = true; let isMounted = true;
@@ -231,17 +232,36 @@ export default withRouter(class LoggedInHome extends React.Component {
} }
deleteProgress = (progressId) => { deleteProgress = (progressId) => {
this.state.db.collection("progress") if (this.state.pendingDeletions[progressId] !== true) {
let pendingDeletions = this.state.pendingDeletions;
pendingDeletions[progressId] = true;
this.setState({
pendingDeletions: pendingDeletions,
});
this.state.db.collection("progress")
.doc(progressId) .doc(progressId)
.delete() .delete()
.then(() => { .then(() => {
const progressIndex = this.state.progressHistoryIncomplete.map((obj) => obj.id).indexOf(progressId); const progressIndex = this.state.progressHistoryIncomplete.map((obj) => obj.id).indexOf(progressId);
let newState = { let newState = {
progressHistoryIncomplete: this.state.progressHistoryIncomplete, progressHistoryIncomplete: this.state.progressHistoryIncomplete,
}; };
newState.progressHistoryIncomplete.splice(progressIndex, 1); newState.progressHistoryIncomplete.splice(progressIndex, 1);
this.setState(newState); newState.pendingDeletions = this.state.pendingDeletions;
}); delete pendingDeletions[progressId];
this.setState(newState);
})
.catch((error) => {
console.log(`Couldn't delete progress: ${error}`);
let pendingDeletions = this.state.pendingDeletions;
delete pendingDeletions[progressId];
this.setState({
pendingDeletions: pendingDeletions,
});
});
}
} }
showTestStart = () => { showTestStart = () => {
@@ -427,6 +447,8 @@ export default withRouter(class LoggedInHome extends React.Component {
className="button--no-background" className="button--no-background"
onClick={() => this.deleteProgress(progressItem.id)} onClick={() => this.deleteProgress(progressItem.id)}
icon={<DeleteRoundedIcon />} icon={<DeleteRoundedIcon />}
disabled={this.state.pendingDeletions[progressItem.id] === true}
loading={this.state.pendingDeletions[progressItem.id] === true}
></Button> ></Button>
</p> </p>
</div> </div>

View File

@@ -485,6 +485,7 @@ export default withRouter(class SetPage extends React.Component {
switchLanguage={this.state.switchLanguage} switchLanguage={this.state.switchLanguage}
handleSwitchLanguageChange={this.handleSwitchLanguageChange} handleSwitchLanguageChange={this.handleSwitchLanguageChange}
loading={this.state.loading} loading={this.state.loading}
disabled={!this.state.canStartTest}
/> />
} }
{ {
@@ -498,6 +499,7 @@ export default withRouter(class SetPage extends React.Component {
switchLanguage={this.state.switchLanguage} switchLanguage={this.state.switchLanguage}
handleSwitchLanguageChange={this.handleSwitchLanguageChange} handleSwitchLanguageChange={this.handleSwitchLanguageChange}
loading={this.state.loading} loading={this.state.loading}
disabled={!this.state.canStartTest}
/> />
} }
{ {