From 1ce340c1c57f9d4e247f31b7269122091f37ed18 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 26 Mar 2022 15:39:50 -0500 Subject: [PATCH 1/2] Make polls look mostly okay --- app/soapbox/components/poll.js | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/app/soapbox/components/poll.js b/app/soapbox/components/poll.js index ee31d25c0..22e06beb0 100644 --- a/app/soapbox/components/poll.js +++ b/app/soapbox/components/poll.js @@ -9,6 +9,7 @@ import spring from 'react-motion/lib/spring'; import { openModal } from 'soapbox/actions/modals'; import { vote, fetchPoll } from 'soapbox/actions/polls'; import Icon from 'soapbox/components/icon'; +import { Text } from 'soapbox/components/ui'; import Motion from 'soapbox/features/ui/util/optional_motion'; import SoapboxPropTypes from 'soapbox/utils/soapbox_prop_types'; @@ -106,7 +107,7 @@ class Poll extends ImmutablePureComponent { {showResults && ( {({ width }) => - + } )} @@ -163,9 +164,15 @@ class Poll extends ImmutablePureComponent {
{!showResults && } - {showResults && !this.props.disabled && · } - - {poll.get('expires_at') && · {timeRemaining}} + + {showResults && !this.props.disabled && ( + · + )} + + {poll.get('expires_at') && · {timeRemaining}} +
); From c0c758c10362e369e3a40f1ed3b9cb3d5fb4c9e2 Mon Sep 17 00:00:00 2001 From: Alex Gleason Date: Sat, 26 Mar 2022 16:20:45 -0500 Subject: [PATCH 2/2] Typescript: reducers/polls.ts --- app/soapbox/reducers/polls.js | 28 ----------------------- app/soapbox/reducers/polls.ts | 39 ++++++++++++++++++++++++++++++++ app/soapbox/reducers/statuses.ts | 3 ++- app/soapbox/types/entities.ts | 2 ++ 4 files changed, 43 insertions(+), 29 deletions(-) delete mode 100644 app/soapbox/reducers/polls.js create mode 100644 app/soapbox/reducers/polls.ts diff --git a/app/soapbox/reducers/polls.js b/app/soapbox/reducers/polls.js deleted file mode 100644 index f9f220edc..000000000 --- a/app/soapbox/reducers/polls.js +++ /dev/null @@ -1,28 +0,0 @@ -import { Map as ImmutableMap } from 'immutable'; - -import { POLLS_IMPORT } from 'soapbox/actions/importer'; -import { normalizeStatus } from 'soapbox/normalizers/status'; - -// HOTFIX: Convert the poll into a fake status to normalize it... -// TODO: get rid of POLLS_IMPORT and use STATUS_IMPORT here. -const normalizePoll = poll => { - const status = { poll }; - return normalizeStatus(status).poll; -}; - -const importPolls = (state, polls) => { - return state.withMutations(map => { - return polls.forEach(poll => map.set(poll.id, normalizePoll(poll))); - }); -}; - -const initialState = ImmutableMap(); - -export default function polls(state = initialState, action) { - switch(action.type) { - case POLLS_IMPORT: - return importPolls(state, action.polls); - default: - return state; - } -} diff --git a/app/soapbox/reducers/polls.ts b/app/soapbox/reducers/polls.ts new file mode 100644 index 000000000..ff6e25567 --- /dev/null +++ b/app/soapbox/reducers/polls.ts @@ -0,0 +1,39 @@ +import { Map as ImmutableMap } from 'immutable'; + +import { POLLS_IMPORT } from 'soapbox/actions/importer'; +import { normalizeStatus } from 'soapbox/normalizers/status'; + +import type { AnyAction } from 'redux'; +import type { Poll, APIEntity, EmbeddedEntity } from 'soapbox/types/entities'; + +type State = ImmutableMap; + +// HOTFIX: Convert the poll into a fake status to normalize it... +// TODO: get rid of POLLS_IMPORT and use STATUS_IMPORT here. +const normalizePoll = (poll: any): EmbeddedEntity => { + const status = { poll }; + return normalizeStatus(status).poll; +}; + +const importPolls = (state: State, polls: Array) => { + return state.withMutations(map => { + return polls.forEach(poll => { + const normalPoll = normalizePoll(poll); + + if (normalPoll && typeof normalPoll === 'object') { + map.set(normalPoll.id, normalPoll); + } + }); + }); +}; + +const initialState: State = ImmutableMap(); + +export default function polls(state: State = initialState, action: AnyAction): State { + switch(action.type) { + case POLLS_IMPORT: + return importPolls(state, action.polls); + default: + return state; + } +} diff --git a/app/soapbox/reducers/statuses.ts b/app/soapbox/reducers/statuses.ts index 3c4f2ce6f..37d78e2c7 100644 --- a/app/soapbox/reducers/statuses.ts +++ b/app/soapbox/reducers/statuses.ts @@ -1,6 +1,5 @@ import escapeTextContentForBrowser from 'escape-html'; import { Map as ImmutableMap, List as ImmutableList } from 'immutable'; -import { AnyAction } from 'redux'; import emojify from 'soapbox/features/emoji/emoji'; import { normalizeStatus } from 'soapbox/normalizers'; @@ -32,6 +31,8 @@ import { } from '../actions/statuses'; import { TIMELINE_DELETE } from '../actions/timelines'; +import type { AnyAction } from 'redux'; + const domParser = new DOMParser(); type StatusRecord = ReturnType; diff --git a/app/soapbox/types/entities.ts b/app/soapbox/types/entities.ts index 65a5bf057..cecdf235d 100644 --- a/app/soapbox/types/entities.ts +++ b/app/soapbox/types/entities.ts @@ -27,6 +27,7 @@ type PollOption = ReturnType; type Status = ReturnType; // Utility types +type APIEntity = Record; type EmbeddedEntity = null | string | ReturnType>; export { @@ -43,5 +44,6 @@ export { Status, // Utility types + APIEntity, EmbeddedEntity, };