Skip to content

Commit

Permalink
Change poll options to alphabetic letters when status text is hidden
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed May 3, 2019
1 parent d77ee3f commit c53d673
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 8 deletions.
14 changes: 8 additions & 6 deletions app/javascript/mastodon/components/poll.js
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ class Poll extends ImmutablePureComponent {
intl: PropTypes.object.isRequired,
dispatch: PropTypes.func,
disabled: PropTypes.bool,
visible: PropTypes.bool,
};

state = {
Expand Down Expand Up @@ -69,13 +70,14 @@ class Poll extends ImmutablePureComponent {
};

renderOption (option, optionIndex) {
const { poll, disabled } = this.props;
const percent = poll.get('votes_count') === 0 ? 0 : (option.get('votes_count') / poll.get('votes_count')) * 100;
const leading = poll.get('options').filterNot(other => other.get('title') === option.get('title')).every(other => option.get('votes_count') > other.get('votes_count'));
const active = !!this.state.selected[`${optionIndex}`];
const showResults = poll.get('voted') || poll.get('expired');
const { poll, disabled, visible } = this.props;
const percent = poll.get('votes_count') === 0 ? 0 : (option.get('votes_count') / poll.get('votes_count')) * 100;
const leading = poll.get('options').filterNot(other => other.get('title') === option.get('title')).every(other => option.get('votes_count') > other.get('votes_count'));
const active = !!this.state.selected[`${optionIndex}`];
const showResults = poll.get('voted') || poll.get('expired');

let titleEmojified = option.get('title_emojified');

if (!titleEmojified) {
const emojiMap = makeEmojiMap(poll);
titleEmojified = emojify(escapeTextContentForBrowser(option.get('title')), emojiMap);
Expand Down Expand Up @@ -104,7 +106,7 @@ class Poll extends ImmutablePureComponent {
{!showResults && <span className={classNames('poll__input', { checkbox: poll.get('multiple'), active })} />}
{showResults && <span className='poll__number'>{Math.round(percent)}%</span>}

<span dangerouslySetInnerHTML={{ __html: titleEmojified }} />
{visible ? <span dangerouslySetInnerHTML={{ __html: titleEmojified }} /> : <span>{String.fromCharCode(64 + optionIndex + 1)}</span>}
</label>
</li>
);
Expand Down
2 changes: 1 addition & 1 deletion app/javascript/mastodon/components/status.js
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ class Status extends ImmutablePureComponent {
}

if (status.get('poll')) {
media = <PollContainer pollId={status.get('poll')} />;
media = <PollContainer pollId={status.get('poll')} visible={!status.get('hidden')} />;
} else if (status.get('media_attachments').size > 0) {
if (this.props.muted) {
media = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ export default class DetailedStatus extends ImmutablePureComponent {
}

if (status.get('poll')) {
media = <PollContainer pollId={status.get('poll')} />;
media = <PollContainer pollId={status.get('poll')} visible={!status.get('hidden')} />;
} else if (status.get('media_attachments').size > 0) {
if (status.getIn(['media_attachments', 0, 'type']) === 'video') {
const video = status.getIn(['media_attachments', 0]);
Expand Down

0 comments on commit c53d673

Please sign in to comment.