Nelze vybrat více než 25 témat Téma musí začínat písmenem nebo číslem, může obsahovat pomlčky („-“) a může být dlouhé až 35 znaků.

PollAnswer.tsx 5.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121
  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
  49. id = 'answer-content'
  50. style = { pollsStyles.answerContent as ViewStyle }>
  51. {
  52. poll.answers.map((answer, index: number) => (
  53. <View
  54. key = { index }
  55. style = { pollsStyles.switchRow as ViewStyle } >
  56. <Switch
  57. checked = { checkBoxStates[index] }
  58. disabled = { poll.saved }
  59. id = 'answer-switch'
  60. onChange = { state => setCheckbox(index, state) } />
  61. <Text style = { pollsStyles.switchLabel as TextStyle }>
  62. { answer.name }
  63. </Text>
  64. </View>
  65. ))
  66. }
  67. </View>
  68. {
  69. pollSaved
  70. ? <View style = { pollsStyles.buttonRow as ViewStyle }>
  71. <Button
  72. accessibilityLabel = 'polls.answer.edit'
  73. id = { t('polls.answer.edit') }
  74. labelKey = 'polls.answer.edit'
  75. onClick = { () => {
  76. setCreateMode(true);
  77. dispatch(editPoll(pollId, true));
  78. } }
  79. style = { pollsStyles.pollCreateButton }
  80. type = { SECONDARY } />
  81. <Button
  82. accessibilityLabel = 'polls.answer.send'
  83. id = { t('polls.answer.send') }
  84. labelKey = 'polls.answer.send'
  85. onClick = { sendPoll }
  86. style = { pollsStyles.pollCreateButton }
  87. type = { PRIMARY } />
  88. </View>
  89. : <View style = { pollsStyles.buttonRow as ViewStyle }>
  90. <Button
  91. accessibilityLabel = 'polls.answer.skip'
  92. id = { t('polls.answer.skip') }
  93. labelKey = 'polls.answer.skip'
  94. onClick = { changingVote ? skipChangeVote : skipAnswer }
  95. style = { pollsStyles.pollCreateButton }
  96. type = { SECONDARY } />
  97. <Button
  98. accessibilityLabel = 'polls.answer.submit'
  99. disabled = { isSubmitAnswerDisabled(checkBoxStates) }
  100. id = { t('polls.answer.submit') }
  101. labelKey = 'polls.answer.submit'
  102. onClick = { submitAnswer }
  103. style = { pollsStyles.pollCreateButton }
  104. type = { PRIMARY } />
  105. </View>
  106. }
  107. </>
  108. );
  109. };
  110. /*
  111. * We apply AbstractPollAnswer to fill in the AbstractProps common
  112. * to both the web and native implementations.
  113. */
  114. // eslint-disable-next-line new-cap
  115. export default AbstractPollAnswer(PollAnswer);