Fix expiring polls not being displayed as such in the WebUI#11835
Fix expiring polls not being displayed as such in the WebUI#11835Gargron merged 4 commits intomastodon:masterfrom
Conversation
Gargron
left a comment
There was a problem hiding this comment.
This is very likely to run into issues when components are re-used by the renderer and passed completely different props.
|
Good point (although honestly that's not something that should happen 😩), I'll look into that |
|
|
||
| state = { | ||
| selected: {}, | ||
| expired: this.props.poll.get('expired') || (new Date(this.props.poll.get('expires_at'))).getTime() < this.props.intl.now(), |
There was a problem hiding this comment.
Set this to null.
Create _setupTimer method. Call this method from componentDidMount. Call this method from componentWillReceiveProps if nextProps.poll.get('expired') !== this.props.poll.get('expired') etc.
There was a problem hiding this comment.
Setting it to null and then changing it in componentDidMount would incur an useless extra render cycle for every poll.
There was a problem hiding this comment.
Well, realistically, there's no reason to store expired in state, for example RelativeTimestamp component stores current timestamp in the state, and then the render method takes care of calculating the difference. That's probably the cleanest approach.
There was a problem hiding this comment.
I'd say there's no reason to store the current timestamp either, tbh.
Changed it to not use the deprecated componentWillReceiveProps and refactor it, it's cleaner imho, and should not do useless renders. However, it will re-fire the timer each time a poll gets updated even if its expiration date does not change. This is infrequent and cheaper than a render, though.
366fa72 to
d489216
Compare
d489216 to
59a201d
Compare
…#11835) * Fix expiring polls not being displayed as such in the WebUI * Reset expiration state and timer when a poll changes * Refactor timer logic in `_setupTimer`, only set expiration if props have changed * Refactor and do not use deprecated React lifecycles
No description provided.