Skip to content

Commit

Permalink
Fix null poll
Browse files Browse the repository at this point in the history
  • Loading branch information
noellabo authored and mashirozx committed Nov 3, 2020
1 parent 19c8d15 commit dc7b06f
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion app/javascript/mastodon/components/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -39,6 +39,9 @@ class Poll extends ImmutablePureComponent {

static getDerivedStateFromProps (props, state) {
const { poll, intl } = props;
if (!poll) {
return null;
}
const expires_at = poll.get('expires_at');
const expired = poll.get('expired') || expires_at !== null && (new Date(expires_at)).getTime() < intl.now();
return (expired === state.expired) ? null : { expired };
Expand All @@ -59,7 +62,7 @@ class Poll extends ImmutablePureComponent {
_setupTimer () {
const { poll, intl } = this.props;
clearTimeout(this._timer);
if (!this.state.expired) {
if (!this.state.expired && !!poll) {
const delay = (new Date(poll.get('expires_at'))).getTime() - intl.now();
this._timer = setTimeout(() => {
this.setState({ expired: true });
Expand Down

0 comments on commit dc7b06f

Please sign in to comment.