Skip to content

Commit fd128b9

Browse files
authored
Fix poll options not rendering text after vote/refresh (#10189)
* Fix poll options not rendering text after vote/refresh * Fix poll options not showing up on public pages * Fix code style issue
1 parent 5764355 commit fd128b9

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

app/javascript/mastodon/actions/importer/index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -82,3 +82,9 @@ export function importFetchedStatuses(statuses) {
8282
dispatch(importStatuses(normalStatuses));
8383
};
8484
}
85+
86+
export function importFetchedPoll(poll) {
87+
return dispatch => {
88+
dispatch(importPolls([normalizePoll(poll)]));
89+
};
90+
}

app/javascript/mastodon/actions/polls.js

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import api from '../api';
2+
import { importFetchedPoll } from './importer';
23

34
export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST';
45
export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS';
@@ -12,15 +13,21 @@ export const vote = (pollId, choices) => (dispatch, getState) => {
1213
dispatch(voteRequest());
1314

1415
api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices })
15-
.then(({ data }) => dispatch(voteSuccess(data)))
16+
.then(({ data }) => {
17+
dispatch(importFetchedPoll(data));
18+
dispatch(voteSuccess(data));
19+
})
1620
.catch(err => dispatch(voteFail(err)));
1721
};
1822

1923
export const fetchPoll = pollId => (dispatch, getState) => {
2024
dispatch(fetchPollRequest());
2125

2226
api(getState).get(`/api/v1/polls/${pollId}`)
23-
.then(({ data }) => dispatch(fetchPollSuccess(data)))
27+
.then(({ data }) => {
28+
dispatch(importFetchedPoll(data));
29+
dispatch(fetchPollSuccess(data));
30+
})
2431
.catch(err => dispatch(fetchPollFail(err)));
2532
};
2633

app/javascript/mastodon/components/poll.js

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import classNames from 'classnames';
77
import { vote, fetchPoll } from 'mastodon/actions/polls';
88
import Motion from 'mastodon/features/ui/util/optional_motion';
99
import spring from 'react-motion/lib/spring';
10+
import escapeTextContentForBrowser from 'escape-html';
11+
import emojify from 'mastodon/features/emoji/emoji';
1012

1113
const messages = defineMessages({
1214
moments: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' },
@@ -120,7 +122,7 @@ class Poll extends ImmutablePureComponent {
120122
{!showResults && <span className={classNames('poll__input', { checkbox: poll.get('multiple'), active })} />}
121123
{showResults && <span className='poll__number'>{Math.round(percent)}%</span>}
122124

123-
<span dangerouslySetInnerHTML={{ __html: option.get('title_emojified') }} />
125+
<span dangerouslySetInnerHTML={{ __html: option.get('title_emojified', emojify(escapeTextContentForBrowser(option.get('title')))) }} />
124126
</label>
125127
</li>
126128
);

app/javascript/mastodon/reducers/polls.js

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
import { POLL_VOTE_SUCCESS, POLL_FETCH_SUCCESS } from 'mastodon/actions/polls';
21
import { POLLS_IMPORT } from 'mastodon/actions/importer';
32
import { Map as ImmutableMap, fromJS } from 'immutable';
43

@@ -10,9 +9,6 @@ export default function polls(state = initialState, action) {
109
switch(action.type) {
1110
case POLLS_IMPORT:
1211
return importPolls(state, action.polls);
13-
case POLL_VOTE_SUCCESS:
14-
case POLL_FETCH_SUCCESS:
15-
return importPolls(state, [action.poll]);
1612
default:
1713
return state;
1814
}

0 commit comments

Comments
 (0)