Вы не можете выбрать более 25 тем Темы должны начинаться с буквы или цифры, могут содержать дефисы(-) и должны содержать не более 35 символов.

PollAnswer.tsx 4.8KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. /* eslint-disable react/jsx-no-bind */
  2. import React from 'react';
  3. import { Text, TextStyle, View, ViewStyle } from 'react-native';
  4. import { useDispatch, useSelector } from 'react-redux';
  5. import { IconCloseLarge } from '../../../base/icons/svg';
  6. import { getLocalParticipant } from '../../../base/participants/functions';
  7. import Button from '../../../base/ui/components/native/Button';
  8. import IconButton from '../../../base/ui/components/native/IconButton';
  9. import Switch from '../../../base/ui/components/native/Switch';
  10. import { BUTTON_TYPES } from '../../../base/ui/constants.native';
  11. import { editPoll, removePoll } from '../../actions';
  12. import { isSubmitAnswerDisabled } from '../../functions';
  13. import AbstractPollAnswer, { AbstractProps } from '../AbstractPollAnswer';
  14. import { dialogStyles, pollsStyles } from './styles';
  15. const PollAnswer = (props: AbstractProps) => {
  16. const {
  17. checkBoxStates,
  18. poll,
  19. pollId,
  20. sendPoll,
  21. setCheckbox,
  22. setCreateMode,
  23. skipAnswer,
  24. skipChangeVote,
  25. submitAnswer,
  26. t
  27. } = props;
  28. const { changingVote, saved: pollSaved } = poll;
  29. const dispatch = useDispatch();
  30. const localParticipant = useSelector(getLocalParticipant);
  31. const { PRIMARY, SECONDARY } = BUTTON_TYPES;
  32. return (
  33. <>
  34. <View style = { dialogStyles.headerContainer as ViewStyle }>
  35. <View>
  36. <Text style = { dialogStyles.questionText as TextStyle } >{ poll.question }</Text>
  37. <Text style = { dialogStyles.questionOwnerText as TextStyle } >{
  38. t('polls.by', { name: localParticipant?.name })
  39. }
  40. </Text>
  41. </View>
  42. {
  43. pollSaved && <IconButton
  44. onPress = { () => dispatch(removePoll(pollId, poll)) }
  45. src = { IconCloseLarge } />
  46. }
  47. </View>
  48. <View style = { pollsStyles.answerContent as ViewStyle }>
  49. {
  50. poll.answers.map((answer, index: number) => (
  51. <View
  52. key = { index }
  53. style = { pollsStyles.switchRow as ViewStyle } >
  54. <Switch
  55. checked = { checkBoxStates[index] }
  56. disabled = { poll.saved }
  57. onChange = { state => setCheckbox(index, state) } />
  58. <Text style = { pollsStyles.switchLabel as TextStyle }>
  59. { answer.name }
  60. </Text>
  61. </View>
  62. ))
  63. }
  64. </View>
  65. {
  66. pollSaved
  67. ? <View style = { pollsStyles.buttonRow as ViewStyle }>
  68. <Button
  69. accessibilityLabel = 'polls.answer.edit'
  70. labelKey = 'polls.answer.edit'
  71. onClick = { () => {
  72. setCreateMode(true);
  73. dispatch(editPoll(pollId, true));
  74. } }
  75. style = { pollsStyles.pollCreateButton }
  76. type = { SECONDARY } />
  77. <Button
  78. accessibilityLabel = 'polls.answer.send'
  79. labelKey = 'polls.answer.send'
  80. onClick = { sendPoll }
  81. style = { pollsStyles.pollCreateButton }
  82. type = { PRIMARY } />
  83. </View>
  84. : <View style = { pollsStyles.buttonRow as ViewStyle }>
  85. <Button
  86. accessibilityLabel = 'polls.answer.skip'
  87. labelKey = 'polls.answer.skip'
  88. onClick = { changingVote ? skipChangeVote : skipAnswer }
  89. style = { pollsStyles.pollCreateButton }
  90. type = { SECONDARY } />
  91. <Button
  92. accessibilityLabel = 'polls.answer.submit'
  93. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  94. labelKey = 'polls.answer.submit'
  95. onClick = { submitAnswer }
  96. style = { pollsStyles.pollCreateButton }
  97. type = { PRIMARY } />
  98. </View>
  99. }
  100. </>
  101. );
  102. };
  103. /*
  104. * We apply AbstractPollAnswer to fill in the AbstractProps common
  105. * to both the web and native implementations.
  106. */
  107. // eslint-disable-next-line new-cap
  108. export default AbstractPollAnswer(PollAnswer);