123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- /* eslint-disable react/jsx-no-bind */
-
- import React from 'react';
- import { Text, TextStyle, View, ViewStyle } from 'react-native';
- import { useDispatch, useSelector } from 'react-redux';
-
- import { IconCloseLarge } from '../../../base/icons/svg';
- import { getLocalParticipant } from '../../../base/participants/functions';
- import Button from '../../../base/ui/components/native/Button';
- import IconButton from '../../../base/ui/components/native/IconButton';
- import Switch from '../../../base/ui/components/native/Switch';
- import { BUTTON_TYPES } from '../../../base/ui/constants.native';
- import { editPoll, removePoll } from '../../actions';
- import { isSubmitAnswerDisabled } from '../../functions';
- import AbstractPollAnswer, { AbstractProps } from '../AbstractPollAnswer';
-
- import { dialogStyles, pollsStyles } from './styles';
-
- const PollAnswer = (props: AbstractProps) => {
- const {
- checkBoxStates,
- poll,
- pollId,
- sendPoll,
- setCheckbox,
- setCreateMode,
- skipAnswer,
- skipChangeVote,
- submitAnswer,
- t
- } = props;
- const { changingVote, saved: pollSaved } = poll;
- const dispatch = useDispatch();
- const localParticipant = useSelector(getLocalParticipant);
- const { PRIMARY, SECONDARY } = BUTTON_TYPES;
-
- return (
- <>
- <View style = { dialogStyles.headerContainer as ViewStyle }>
- <View>
- <Text style = { dialogStyles.questionText as TextStyle } >{ poll.question }</Text>
- <Text style = { dialogStyles.questionOwnerText as TextStyle } >{
- t('polls.by', { name: localParticipant?.name })
- }
- </Text>
- </View>
- {
- pollSaved && <IconButton
- onPress = { () => dispatch(removePoll(pollId, poll)) }
- src = { IconCloseLarge } />
- }
- </View>
- <View style = { pollsStyles.answerContent as ViewStyle }>
- {
- poll.answers.map((answer, index: number) => (
- <View
- key = { index }
- style = { pollsStyles.switchRow as ViewStyle } >
- <Switch
- checked = { checkBoxStates[index] }
- disabled = { poll.saved }
- onChange = { state => setCheckbox(index, state) } />
- <Text style = { pollsStyles.switchLabel as TextStyle }>
- { answer.name }
- </Text>
- </View>
- ))
- }
- </View>
- {
- pollSaved
- ? <View style = { pollsStyles.buttonRow as ViewStyle }>
- <Button
- accessibilityLabel = 'polls.answer.edit'
- labelKey = 'polls.answer.edit'
- onClick = { () => {
- setCreateMode(true);
- dispatch(editPoll(pollId, true));
- } }
- style = { pollsStyles.pollCreateButton }
- type = { SECONDARY } />
- <Button
- accessibilityLabel = 'polls.answer.send'
- labelKey = 'polls.answer.send'
- onClick = { sendPoll }
- style = { pollsStyles.pollCreateButton }
- type = { PRIMARY } />
- </View>
- : <View style = { pollsStyles.buttonRow as ViewStyle }>
- <Button
- accessibilityLabel = 'polls.answer.skip'
- labelKey = 'polls.answer.skip'
- onClick = { changingVote ? skipChangeVote : skipAnswer }
- style = { pollsStyles.pollCreateButton }
- type = { SECONDARY } />
- <Button
- accessibilityLabel = 'polls.answer.submit'
- disabled = { isSubmitAnswerDisabled(checkBoxStates) }
- labelKey = 'polls.answer.submit'
- onClick = { submitAnswer }
- style = { pollsStyles.pollCreateButton }
- type = { PRIMARY } />
- </View>
- }
- </>
- );
- };
-
- /*
- * We apply AbstractPollAnswer to fill in the AbstractProps common
- * to both the web and native implementations.
- */
- // eslint-disable-next-line new-cap
- export default AbstractPollAnswer(PollAnswer);
|