Skip to content

Commit

Permalink
[#205] Resolve async setState issue
Browse files Browse the repository at this point in the history
  • Loading branch information
palagdan authored and blcham committed Nov 7, 2024
1 parent 05a1407 commit 2d0ce68
Showing 1 changed file with 16 additions and 18 deletions.
34 changes: 16 additions & 18 deletions src/components/record/RecordController.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -130,37 +130,35 @@ class RecordController extends React.Component {
};

_onComplete = () => {
this._handlePhaseChange(RECORD_PHASE.COMPLETED);
this._transitionToRecords();
this._handlePhaseChange(RECORD_PHASE.COMPLETED, () => {
this._handleRejectMessage(null, () => {
this.props.updateRecord(this.state.record, this.props.currentUser);
this._transitionToRecords();
});
});
};

_onReject = (reason) => {
this._handlePhaseChange(RECORD_PHASE.REJECTED);
this._handleRejectMessage(reason);
this._transitionToRecords();
this._handlePhaseChange(RECORD_PHASE.REJECTED, () => {
this._handleRejectMessage(reason, () => {
this.props.updateRecord(this.state.record, this.props.currentUser);
this._transitionToRecords();
});
});
};

_handleRejectMessage(reason) {
const currentUser = this.props.currentUser;
_handleRejectMessage(reason, callback) {
const update = { ...this.state.record, rejectMessage: reason };
console.log(this.state.record);
this.setState({ record: update });

this.props.updateRecord(update, currentUser);
this.setState({ record: update }, callback);
}

_handlePhaseChange = (newPhase) => {
const currentUser = this.props.currentUser;
_handlePhaseChange = (newPhase, callback) => {
const update = { ...this.state.record, phase: newPhase };

this.setState({ record: update });

this.props.updateRecord(update, currentUser);
this.setState({ record: update }, callback);
};

_getLocalName() {
if (EXTENSIONS.split(",").includes("kodi")) {
// return name of the record based on answer of specific question
return this._getKodiLocaLName();
}
return "record-" + Date.now();
Expand Down

0 comments on commit 2d0ce68

Please sign in to comment.