You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

PollAnswer.tsx 2.8KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  1. /* eslint-disable lines-around-comment */
  2. import React from 'react';
  3. import { Text, View } from 'react-native';
  4. import { useSelector } from 'react-redux';
  5. import { getLocalParticipant } from '../../../base/participants/functions';
  6. import Button from '../../../base/ui/components/native/Button';
  7. import Switch from '../../../base/ui/components/native/Switch';
  8. import { BUTTON_TYPES } from '../../../base/ui/constants.native';
  9. import { isSubmitAnswerDisabled } from '../../functions';
  10. import AbstractPollAnswer, { AbstractProps } from '../AbstractPollAnswer';
  11. // @ts-ignore
  12. import { chatStyles, dialogStyles } from './styles';
  13. const PollAnswer = (props: AbstractProps) => {
  14. const {
  15. checkBoxStates,
  16. poll,
  17. setCheckbox,
  18. skipAnswer,
  19. skipChangeVote,
  20. submitAnswer,
  21. t
  22. } = props;
  23. const { changingVote } = poll;
  24. const localParticipant = useSelector(getLocalParticipant);
  25. const { PRIMARY, SECONDARY } = BUTTON_TYPES;
  26. return (
  27. <>
  28. <Text style = { dialogStyles.questionText } >{ poll.question }</Text>
  29. <Text style = { dialogStyles.questionOwnerText } >{
  30. t('polls.by', { name: localParticipant?.name })
  31. }
  32. </Text>
  33. <View style = { chatStyles.answerContent }>
  34. {poll.answers.map((answer, index) => (
  35. <View
  36. key = { index }
  37. style = { chatStyles.switchRow } >
  38. <Switch
  39. checked = { checkBoxStates[index] }
  40. /* eslint-disable-next-line react/jsx-no-bind */
  41. onChange = { state => setCheckbox(index, state) } />
  42. <Text style = { chatStyles.switchLabel }>{answer.name}</Text>
  43. </View>
  44. ))}
  45. </View>
  46. <View style = { chatStyles.buttonRow }>
  47. <Button
  48. accessibilityLabel = 'polls.answer.skip'
  49. labelKey = 'polls.answer.skip'
  50. onClick = { changingVote ? skipChangeVote : skipAnswer }
  51. style = { chatStyles.pollCreateButton }
  52. type = { SECONDARY } />
  53. <Button
  54. accessibilityLabel = 'polls.answer.submit'
  55. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  56. labelKey = 'polls.answer.submit'
  57. onClick = { submitAnswer }
  58. style = { chatStyles.pollCreateButton }
  59. type = { PRIMARY } />
  60. </View>
  61. </>
  62. );
  63. };
  64. /*
  65. * We apply AbstractPollAnswer to fill in the AbstractProps common
  66. * to both the web and native implementations.
  67. */
  68. // eslint-disable-next-line new-cap
  69. export default AbstractPollAnswer(PollAnswer);