From 7f32d675b05b012a80c2b34c07d361ec8d596bf3 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 03:57:46 +0100 Subject: Render unicode emoji in polls using emoji pack Port 4407f07014096bcbaf5a06015a5791984282846d to glitch-soc --- app/javascript/flavours/glitch/actions/importer/index.js | 4 ++-- app/javascript/flavours/glitch/actions/importer/normalizer.js | 11 +++++++++++ app/javascript/flavours/glitch/components/poll.js | 2 +- 3 files changed, 14 insertions(+), 3 deletions(-) (limited to 'app/javascript/flavours/glitch') diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js index abadee817..e990dc04c 100644 --- a/app/javascript/flavours/glitch/actions/importer/index.js +++ b/app/javascript/flavours/glitch/actions/importer/index.js @@ -1,4 +1,4 @@ -import { normalizeAccount, normalizeStatus } from './normalizer'; +import { normalizeAccount, normalizeStatus, normalizePoll } from './normalizer'; export const ACCOUNT_IMPORT = 'ACCOUNT_IMPORT'; export const ACCOUNTS_IMPORT = 'ACCOUNTS_IMPORT'; @@ -71,7 +71,7 @@ export function importFetchedStatuses(statuses) { } if (status.poll && status.poll.id) { - pushUnique(polls, status.poll); + pushUnique(polls, normalizePoll(status.poll)); } } diff --git a/app/javascript/flavours/glitch/actions/importer/normalizer.js b/app/javascript/flavours/glitch/actions/importer/normalizer.js index f57fb70b4..ccd84364e 100644 --- a/app/javascript/flavours/glitch/actions/importer/normalizer.js +++ b/app/javascript/flavours/glitch/actions/importer/normalizer.js @@ -65,3 +65,14 @@ export function normalizeStatus(status, normalOldStatus) { return normalStatus; } + +export function normalizePoll(poll) { + const normalPoll = { ...poll }; + + normalPoll.options = poll.options.map(option => ({ + ...option, + title_emojified: emojify(escapeTextContentForBrowser(option.title)), + })); + + return normalPoll; +} diff --git a/app/javascript/flavours/glitch/components/poll.js b/app/javascript/flavours/glitch/components/poll.js index 182491af8..c52445c86 100644 --- a/app/javascript/flavours/glitch/components/poll.js +++ b/app/javascript/flavours/glitch/components/poll.js @@ -120,7 +120,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - {option.get('title')} + ); -- cgit From 94f1a751bf0313249d891e760dc758e621f1b9ad Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 04:54:32 +0100 Subject: Avoid line breaks in poll options Port 57643557b64bc1853c4aeb65fc652dac3467fa18 to glitch-soc --- app/javascript/flavours/glitch/styles/polls.scss | 4 ++++ 1 file changed, 4 insertions(+) (limited to 'app/javascript/flavours/glitch') diff --git a/app/javascript/flavours/glitch/styles/polls.scss b/app/javascript/flavours/glitch/styles/polls.scss index 7c6e61d63..ce324b36e 100644 --- a/app/javascript/flavours/glitch/styles/polls.scss +++ b/app/javascript/flavours/glitch/styles/polls.scss @@ -5,6 +5,7 @@ li { margin-bottom: 10px; position: relative; + height: 18px + 12px; } &__chart { @@ -27,6 +28,9 @@ padding: 6px 0; line-height: 18px; cursor: default; + white-space: nowrap; + overflow: hidden; + text-overflow: ellipsis; input[type=radio], input[type=checkbox] { -- cgit From 94a0149ff3e455792050e790d397d1d4d2c2d851 Mon Sep 17 00:00:00 2001 From: Eugen Rochko Date: Wed, 6 Mar 2019 05:35:52 +0100 Subject: Fix poll options not rendering text after vote/refresh Port fd128b9c7aa5c71adbfc2e223212514c0baee675 to glitch-soc --- app/javascript/flavours/glitch/actions/importer/index.js | 6 ++++++ app/javascript/flavours/glitch/actions/polls.js | 11 +++++++++-- app/javascript/flavours/glitch/components/poll.js | 4 +++- app/javascript/flavours/glitch/reducers/polls.js | 4 ---- 4 files changed, 18 insertions(+), 7 deletions(-) (limited to 'app/javascript/flavours/glitch') diff --git a/app/javascript/flavours/glitch/actions/importer/index.js b/app/javascript/flavours/glitch/actions/importer/index.js index e990dc04c..f4372fb31 100644 --- a/app/javascript/flavours/glitch/actions/importer/index.js +++ b/app/javascript/flavours/glitch/actions/importer/index.js @@ -82,3 +82,9 @@ export function importFetchedStatuses(statuses) { dispatch(importStatuses(normalStatuses)); }; } + +export function importFetchedPoll(poll) { + return dispatch => { + dispatch(importPolls([normalizePoll(poll)])); + }; +} diff --git a/app/javascript/flavours/glitch/actions/polls.js b/app/javascript/flavours/glitch/actions/polls.js index bee4c48a6..8e8b82df5 100644 --- a/app/javascript/flavours/glitch/actions/polls.js +++ b/app/javascript/flavours/glitch/actions/polls.js @@ -1,4 +1,5 @@ import api from '../api'; +import { importFetchedPoll } from './importer'; export const POLL_VOTE_REQUEST = 'POLL_VOTE_REQUEST'; export const POLL_VOTE_SUCCESS = 'POLL_VOTE_SUCCESS'; @@ -12,7 +13,10 @@ export const vote = (pollId, choices) => (dispatch, getState) => { dispatch(voteRequest()); api(getState).post(`/api/v1/polls/${pollId}/votes`, { choices }) - .then(({ data }) => dispatch(voteSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(voteSuccess(data)); + }) .catch(err => dispatch(voteFail(err))); }; @@ -20,7 +24,10 @@ export const fetchPoll = pollId => (dispatch, getState) => { dispatch(fetchPollRequest()); api(getState).get(`/api/v1/polls/${pollId}`) - .then(({ data }) => dispatch(fetchPollSuccess(data))) + .then(({ data }) => { + dispatch(importFetchedPoll(data)); + dispatch(fetchPollSuccess(data)); + }) .catch(err => dispatch(fetchPollFail(err))); }; diff --git a/app/javascript/flavours/glitch/components/poll.js b/app/javascript/flavours/glitch/components/poll.js index c52445c86..bfff7b601 100644 --- a/app/javascript/flavours/glitch/components/poll.js +++ b/app/javascript/flavours/glitch/components/poll.js @@ -7,6 +7,8 @@ import classNames from 'classnames'; import { vote, fetchPoll } from 'mastodon/actions/polls'; import Motion from 'mastodon/features/ui/util/optional_motion'; import spring from 'react-motion/lib/spring'; +import escapeTextContentForBrowser from 'escape-html'; +import emojify from 'mastodon/features/emoji/emoji'; const messages = defineMessages({ moments: { id: 'time_remaining.moments', defaultMessage: 'Moments remaining' }, @@ -120,7 +122,7 @@ class Poll extends ImmutablePureComponent { {!showResults && } {showResults && {Math.round(percent)}%} - + ); diff --git a/app/javascript/flavours/glitch/reducers/polls.js b/app/javascript/flavours/glitch/reducers/polls.js index 53d9b1d8c..9956cf83f 100644 --- a/app/javascript/flavours/glitch/reducers/polls.js +++ b/app/javascript/flavours/glitch/reducers/polls.js @@ -1,4 +1,3 @@ -import { POLL_VOTE_SUCCESS, POLL_FETCH_SUCCESS } from 'mastodon/actions/polls'; import { POLLS_IMPORT } from 'mastodon/actions/importer'; import { Map as ImmutableMap, fromJS } from 'immutable'; @@ -10,9 +9,6 @@ export default function polls(state = initialState, action) { switch(action.type) { case POLLS_IMPORT: return importPolls(state, action.polls); - case POLL_VOTE_SUCCESS: - case POLL_FETCH_SUCCESS: - return importPolls(state, [action.poll]); default: return state; } -- cgit