From 70af0d6b7813ede32eb101198a4cfffb37d8a514 Mon Sep 17 00:00:00 2001 From: Vlad Piersec Date: Tue, 12 Oct 2021 14:04:16 +0300 Subject: [PATCH] fix(polls): Fix 'Skip' button functionality --- react/features/polls/actionTypes.js | 11 +++++ react/features/polls/actions.js | 21 ++++++++++ .../polls/components/AbstractPollAnswer.js | 8 +++- .../polls/components/AbstractPollResults.js | 41 +++++++------------ .../polls/components/native/PollAnswer.js | 4 +- .../polls/components/native/PollItem.js | 2 +- .../polls/components/web/PollAnswer.js | 4 +- .../features/polls/components/web/PollItem.js | 2 +- react/features/polls/functions.js | 22 ++++++++-- react/features/polls/reducer.js | 18 ++++++++ react/features/polls/subscriber.js | 2 + react/features/polls/types.js | 5 +++ 12 files changed, 105 insertions(+), 35 deletions(-) diff --git a/react/features/polls/actionTypes.js b/react/features/polls/actionTypes.js index 3b7ff84cb..f48b725c1 100644 --- a/react/features/polls/actionTypes.js +++ b/react/features/polls/actionTypes.js @@ -1,5 +1,16 @@ // @flow +/** + * The type of the action which signals that a Poll will be changed + * + * { + * type: CHANGE_VOTE, + * } + * + */ +export const CHANGE_VOTE = 'CHANGE_VOTE'; + + /** * The type of the action which signals that a new Poll was received. * diff --git a/react/features/polls/actions.js b/react/features/polls/actions.js index df3b8590b..af7a94798 100644 --- a/react/features/polls/actions.js +++ b/react/features/polls/actions.js @@ -1,6 +1,7 @@ // @flow import { + CHANGE_VOTE, RESET_NB_UNREAD_POLLS, RECEIVE_ANSWER, RECEIVE_POLL, @@ -9,6 +10,26 @@ import { } from './actionTypes'; import type { Answer, Poll } from './types'; +/** + * Action to signal that a poll's vote will be changed. + * + * @param {string} pollId - The id of the incoming poll. + * @param {boolean} value - The value of the 'changing' state. + + * @returns {{ + * type: CHANGE_VOTE, + * pollId: string, + * value: boolean + * }} + */ +export const setVoteChanging = (pollId: string, value: boolean) => { + return { + type: CHANGE_VOTE, + pollId, + value + }; +}; + /** * Action to signal that a new poll was received. * diff --git a/react/features/polls/components/AbstractPollAnswer.js b/react/features/polls/components/AbstractPollAnswer.js index ee1dcde1b..e0f5e7cbc 100644 --- a/react/features/polls/components/AbstractPollAnswer.js +++ b/react/features/polls/components/AbstractPollAnswer.js @@ -7,7 +7,7 @@ import { useDispatch, useSelector } from 'react-redux'; import { sendAnalytics, createPollEvent } from '../../analytics'; import { getLocalParticipant, getParticipantById } from '../../base/participants'; -import { registerVote } from '../actions'; +import { registerVote, setVoteChanging } from '../actions'; import { COMMAND_ANSWER_POLL } from '../constants'; import type { Poll } from '../types'; @@ -27,6 +27,7 @@ export type AbstractProps = { poll: Poll, setCheckbox: Function, skipAnswer: Function, + skipChangeVote: Function, submitAnswer: Function, t: Function, }; @@ -90,6 +91,10 @@ const AbstractPollAnswer = (Component: AbstractComponent) => (pro }, [ pollId ]); + const skipChangeVote = useCallback(() => { + dispatch(setVoteChanging(pollId, false)); + }, [ dispatch, pollId ]); + const { t } = useTranslation(); return () => (pro poll = { poll } setCheckbox = { setCheckbox } skipAnswer = { skipAnswer } + skipChangeVote = { skipChangeVote } submitAnswer = { submitAnswer } t = { t } />); diff --git a/react/features/polls/components/AbstractPollResults.js b/react/features/polls/components/AbstractPollResults.js index 1be0209a4..939849fa1 100644 --- a/react/features/polls/components/AbstractPollResults.js +++ b/react/features/polls/components/AbstractPollResults.js @@ -6,9 +6,8 @@ import { useTranslation } from 'react-i18next'; import { useDispatch, useSelector } from 'react-redux'; import { sendAnalytics, createPollEvent } from '../../analytics'; -import { getLocalParticipant, getParticipantById } from '../../base/participants/functions'; -import { retractVote } from '../actions'; -import { COMMAND_ANSWER_POLL } from '../constants'; +import { setVoteChanging } from '../actions'; +import { getPoll } from '../functions'; /** * The type of the React {@code Component} props of inheriting component. @@ -51,7 +50,7 @@ export type AbstractProps = { const AbstractPollResults = (Component: AbstractComponent) => (props: InputProps) => { const { pollId } = props; - const pollDetails = useSelector(state => state['features/polls'].polls[pollId]); + const pollDetails = useSelector(getPoll(pollId)); const [ showDetails, setShowDetails ] = useState(false); const toggleIsDetailed = useCallback(() => { @@ -95,33 +94,23 @@ const AbstractPollResults = (Component: AbstractComponent) => (pr }, [ pollDetails.answers, showDetails ]); const dispatch = useDispatch(); - - const conference: Object = useSelector(state => state['features/base/conference'].conference); - const localId = useSelector(state => getLocalParticipant(state).id); - const localParticipant = useSelector(state => getParticipantById(state, localId)); - const localName: string = localParticipant ? localParticipant.name : 'Fellow Jitster'; const changeVote = useCallback(() => { - conference.sendMessage({ - type: COMMAND_ANSWER_POLL, - pollId, - voterId: localId, - voterName: localName, - answers: new Array(pollDetails.answers.length).fill(false) - }); - dispatch(retractVote(pollId)); + dispatch(setVoteChanging(pollId, true)); sendAnalytics(createPollEvent('vote.changed')); - }, [ pollId, localId, localName, pollDetails ]); + }, [ dispatch, pollId ]); const { t } = useTranslation(); - return (); + return ( + + ); }; export default AbstractPollResults; diff --git a/react/features/polls/components/native/PollAnswer.js b/react/features/polls/components/native/PollAnswer.js index 2bbf4b547..ba0b076d5 100644 --- a/react/features/polls/components/native/PollAnswer.js +++ b/react/features/polls/components/native/PollAnswer.js @@ -18,9 +18,11 @@ const PollAnswer = (props: AbstractProps) => { poll, setCheckbox, skipAnswer, + skipChangeVote, submitAnswer, t } = props; + const { changingVote } = poll; return ( @@ -44,7 +46,7 @@ const PollAnswer = (props: AbstractProps) => { diff --git a/react/features/polls/components/native/PollItem.js b/react/features/polls/components/native/PollItem.js index 2b9722a40..50fbeea2e 100644 --- a/react/features/polls/components/native/PollItem.js +++ b/react/features/polls/components/native/PollItem.js @@ -20,7 +20,7 @@ type Props = { } const PollItem = ({ pollId }: Props) => { - const showResults = useSelector(state => shouldShowResults(state, pollId)); + const showResults = useSelector(shouldShowResults(pollId)); return ( { poll, setCheckbox, skipAnswer, + skipChangeVote, submitAnswer, t } = props; + const { changingVote } = poll; return (
@@ -45,7 +47,7 @@ const PollAnswer = (props: AbstractProps) => {