summaryrefslogtreecommitdiff
path: root/src/components/modals/Modal.js
diff options
context:
space:
mode:
authorGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-08-10 12:40:36 +0300
committerGeorgios Andreadis <g.andreadis@student.tudelft.nl>2017-09-23 10:05:28 +0200
commit737ce62470a13ae153788207719396e107252955 (patch)
treecf95bb155fd33bad3c2234d123929e41da738d82 /src/components/modals/Modal.js
parent0bc393e41c5b238c1d95a49ede3dec45b4ed527e (diff)
Suppress duplicate modal close actions
Diffstat (limited to 'src/components/modals/Modal.js')
-rw-r--r--src/components/modals/Modal.js31
1 files changed, 24 insertions, 7 deletions
diff --git a/src/components/modals/Modal.js b/src/components/modals/Modal.js
index bb8fa00f..e7054fec 100644
--- a/src/components/modals/Modal.js
+++ b/src/components/modals/Modal.js
@@ -10,29 +10,46 @@ class Modal extends React.Component {
};
static idCounter = 0;
+ // Local, up-to-date copy of modal visibility for time between close and props update (to prevent duplicate close
+ // triggers)
+ visible = false;
+
constructor() {
super();
- this.id = "modal-" + Modal.idCounter;
+ this.id = "modal-" + Modal.idCounter++;
}
componentDidMount() {
+ this.visible = this.props.show;
this.openOrCloseModal();
- window["$"]("#" + this.id).on("hide.bs.modal", this.props.onCancel.bind(this));
+ window["$"]("#" + this.id).on("hide.bs.modal", () => {
+ if (this.visible) {
+ this.props.onCancel();
+ console.log("TEST");
+ }
+ });
}
componentDidUpdate() {
+ this.visible = this.props.show;
this.openOrCloseModal();
}
onSubmit() {
- this.props.onSubmit();
- this.closeModal();
+ if (this.visible) {
+ this.props.onSubmit();
+ this.visible = false;
+ this.closeModal();
+ }
}
onCancel() {
- this.props.onCancel();
- this.closeModal();
+ if (this.visible) {
+ this.props.onCancel();
+ this.visible = false;
+ this.closeModal();
+ }
}
openModal() {
@@ -44,7 +61,7 @@ class Modal extends React.Component {
}
openOrCloseModal() {
- if (this.props.show) {
+ if (this.visible) {
this.openModal();
} else {
this.closeModal();