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 3.0KB

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