~cytrogen/masto-fe

a117c953d00848b0a4877a7f00400caba29cc0f3 — Eugen Rochko 2 years ago b3f2093
[Glitch] Add button to see results for polls in web UI

Port b7910bc7512b8c08e6d4e8233e0d90aab0c7f35d to glitch-soc

Signed-off-by: Claire <claire.github-309c@sitedethib.com>
1 files changed, 9 insertions(+), 4 deletions(-)

M app/javascript/flavours/glitch/components/poll.jsx
M app/javascript/flavours/glitch/components/poll.jsx => app/javascript/flavours/glitch/components/poll.jsx +9 -4
@@ 131,6 131,10 @@ class Poll extends ImmutablePureComponent {
    this.props.refresh();
  };

  handleReveal = () => {
    this.setState({ revealed: true });
  }

  renderOption (option, optionIndex, showResults) {
    const { poll, lang, disabled, intl } = this.props;
    const pollVotesCount  = poll.get('voters_count') || poll.get('votes_count');


@@ 206,14 210,14 @@ class Poll extends ImmutablePureComponent {

  render () {
    const { poll, intl } = this.props;
    const { expired } = this.state;
    const { revealed, expired } = this.state;

    if (!poll) {
      return null;
    }

    const timeRemaining = expired ? intl.formatMessage(messages.closed) : <RelativeTimestamp timestamp={poll.get('expires_at')} futureDate />;
    const showResults   = poll.get('voted') || expired;
    const showResults   = poll.get('voted') || revealed || expired;
    const disabled      = this.props.disabled || Object.entries(this.state.selected).every(item => !item);

    let votesCount = null;


@@ 232,9 236,10 @@ class Poll extends ImmutablePureComponent {

        <div className='poll__footer'>
          {!showResults && <button className='button button-secondary' disabled={disabled || !this.context.identity.signedIn} onClick={this.handleVote}><FormattedMessage id='poll.vote' defaultMessage='Vote' /></button>}
          {showResults && !this.props.disabled && <span><button className='poll__link' onClick={this.handleRefresh}><FormattedMessage id='poll.refresh' defaultMessage='Refresh' /></button> · </span>}
          {!showResults && <><button className='poll__link' onClick={this.handleReveal}><FormattedMessage id='poll.reveal' defaultMessage='See results' /></button> · </>}
          {showResults && !this.props.disabled && <><button className='poll__link' onClick={this.handleRefresh}><FormattedMessage id='poll.refresh' defaultMessage='Refresh' /></button> · </>}
          {votesCount}
          {poll.get('expires_at') && <span> · {timeRemaining}</span>}
          {poll.get('expires_at') && <> · {timeRemaining}</>}
        </div>
      </div>
    );