Skip to content

Commit

Permalink
fix: Ephemere component
Browse files Browse the repository at this point in the history
handle unmount
  • Loading branch information
stropitek committed Sep 26, 2017
1 parent 580b952 commit 45af857
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 12 deletions.
42 changes: 33 additions & 9 deletions src/client/components/Ephemere.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,43 @@ class Ephemere extends Component {
);
}

componentWillMount() {
this.setTimer();
}

componentDidMount() {
this.makeVisible();
}

componentDidUpdate() {
this.makeVisible();
}

componentWillUpdate() {
if (this.refs.ephemere) {
this.refs.ephemere.style.display = 'block';
}
this.clearTimer();
this.setTimer();
}

componentWillUnmount() {
this.clearTimer();
}
makeVisible() {
if (this.timeout) {
clearTimeout(this.timeout);
if (this.refs.ephemere) {
this.refs.ephemere.style.display = 'block';
}
}
}

componentDidUpdate() {
this.timeout = setTimeout(() => {
this.refs.ephemere.style.display = 'none';
}, this.props.timeout || 3000);
clearTimer() {
clearTimeout(this.timeout);
this.timeout = null;
}
setTimer() {
if (!this.timeout) {
this.timeout = setTimeout(() => {
this.refs.ephemere.style.display = 'none';
}, this.props.timeout || 3000);
}
}
}

Expand Down
4 changes: 1 addition & 3 deletions src/client/components/GroupEditor.js
Original file line number Diff line number Diff line change
Expand Up @@ -67,9 +67,7 @@ class GroupEditor extends PureComponent {
/>
</div>
</div>
<Ephemere>
{group.success ? <div className="alert alert-success">{group.success}</div> : null }
</Ephemere>
{group.success ? <Ephemere><div className="alert alert-success">{group.success}</div></Ephemere> : null }
{group.error ? <div className="alert alert-danger">{group.error}</div> : null }
</div>
</div>
Expand Down

0 comments on commit 45af857

Please sign in to comment.