Skip to content

Commit 7ce0a3c

Browse files
brawarujesseplusplus
authored andcommitted
Add single option votes tooltip in polls (mastodon#16849)
Adds a tooltip when hovering over the percentages in a poll showing how many votes were cast for that option. Also removes descriptions from messages here since they are not picked up by Crowdin anyway and might be confusing to other developers :) Fixes mastodon#16820
1 parent b8eb2ae commit 7ce0a3c

1 file changed

Lines changed: 22 additions & 5 deletions

File tree

  • app/javascript/mastodon/components

app/javascript/mastodon/components/poll.js

Lines changed: 22 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,18 @@ import RelativeTimestamp from './relative_timestamp';
1212
import Icon from 'mastodon/components/icon';
1313

1414
const messages = defineMessages({
15-
closed: { id: 'poll.closed', defaultMessage: 'Closed' },
16-
voted: { id: 'poll.voted', defaultMessage: 'You voted for this answer', description: 'Tooltip of the "voted" checkmark in polls' },
15+
closed: {
16+
id: 'poll.closed',
17+
defaultMessage: 'Closed',
18+
},
19+
voted: {
20+
id: 'poll.voted',
21+
defaultMessage: 'You voted for this answer',
22+
},
23+
votes: {
24+
id: 'poll.votes',
25+
defaultMessage: '{votes, plural, one {# vote} other {# votes}}',
26+
},
1727
});
1828

1929
const makeEmojiMap = record => record.get('emojis').reduce((obj, emoji) => {
@@ -148,9 +158,16 @@ class Poll extends ImmutablePureComponent {
148158
data-index={optionIndex}
149159
/>
150160
)}
151-
{showResults && <span className='poll__number'>
152-
{Math.round(percent)}%
153-
</span>}
161+
{showResults && (
162+
<span
163+
className='poll__number'
164+
title={intl.formatMessage(messages.votes, {
165+
votes: option.get('votes_count'),
166+
})}
167+
>
168+
{Math.round(percent)}%
169+
</span>
170+
)}
154171

155172
<span
156173
className='poll__option__text translate'

0 commit comments

Comments
 (0)