Du kan inte välja fler än 25 ämnen Ämnen måste starta med en bokstav eller siffra, kan innehålla bindestreck ('-') och vara max 35 tecken långa.

ModeratorSection.tsx 4.4KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127
  1. import React, { useCallback, useMemo } from 'react';
  2. import { useDispatch, useSelector } from 'react-redux';
  3. import { IReduxState } from '../../../app/types';
  4. import {
  5. setFollowMe,
  6. setFollowMeRecorder,
  7. setStartMutedPolicy,
  8. setStartReactionsMuted
  9. } from '../../../base/conference/actions';
  10. import { updateSettings } from '../../../base/settings/actions';
  11. import Switch from '../../../base/ui/components/native/Switch';
  12. import { getModeratorTabProps } from '../../functions.native';
  13. import FormRow from './FormRow';
  14. import FormSection from './FormSection';
  15. const ModeratorSection = () => {
  16. const dispatch = useDispatch();
  17. const {
  18. followMeActive,
  19. followMeEnabled,
  20. followMeRecorderActive,
  21. followMeRecorderEnabled,
  22. startAudioMuted,
  23. startVideoMuted,
  24. startReactionsMuted
  25. } = useSelector((state: IReduxState) => getModeratorTabProps(state));
  26. const { disableReactionsModeration } = useSelector((state: IReduxState) => state['features/base/config']);
  27. const onStartAudioMutedToggled = useCallback((enabled?: boolean) => {
  28. dispatch(setStartMutedPolicy(
  29. Boolean(enabled), Boolean(startVideoMuted)));
  30. }, [ startVideoMuted, dispatch, setStartMutedPolicy ]);
  31. const onStartVideoMutedToggled = useCallback((enabled?: boolean) => {
  32. dispatch(setStartMutedPolicy(
  33. Boolean(startAudioMuted), Boolean(enabled)));
  34. }, [ startAudioMuted, dispatch, setStartMutedPolicy ]);
  35. const onFollowMeToggled = useCallback((enabled?: boolean) => {
  36. dispatch(setFollowMe(Boolean(enabled)));
  37. }, [ dispatch, setFollowMe ]);
  38. const onFollowMeRecorderToggled = useCallback((enabled?: boolean) => {
  39. dispatch(setFollowMeRecorder(Boolean(enabled)));
  40. }, [ dispatch, setFollowMeRecorder ]);
  41. const onStartReactionsMutedToggled = useCallback((enabled?: boolean) => {
  42. dispatch(setStartReactionsMuted(Boolean(enabled), true));
  43. dispatch(updateSettings({ soundsReactions: enabled }));
  44. }, [ dispatch, updateSettings, setStartReactionsMuted ]);
  45. const followMeRecorderChecked = followMeRecorderEnabled && !followMeRecorderActive;
  46. const moderationSettings = useMemo(() => {
  47. const moderation = [
  48. {
  49. disabled: false,
  50. label: 'settings.startAudioMuted',
  51. state: startAudioMuted,
  52. onChange: onStartAudioMutedToggled
  53. },
  54. {
  55. disabled: false,
  56. label: 'settings.startVideoMuted',
  57. state: startVideoMuted,
  58. onChange: onStartVideoMutedToggled
  59. },
  60. {
  61. disabled: followMeActive || followMeRecorderActive,
  62. label: 'settings.followMe',
  63. state: followMeEnabled && !followMeActive && !followMeRecorderChecked,
  64. onChange: onFollowMeToggled
  65. },
  66. {
  67. disabled: followMeRecorderActive || followMeActive,
  68. label: 'settings.followMeRecorder',
  69. state: followMeRecorderChecked,
  70. onChange: onFollowMeRecorderToggled
  71. },
  72. {
  73. disabled: false,
  74. label: 'settings.startReactionsMuted',
  75. state: startReactionsMuted,
  76. onChange: onStartReactionsMutedToggled
  77. }
  78. ];
  79. if (disableReactionsModeration) {
  80. moderation.pop();
  81. }
  82. return moderation;
  83. }, [ startAudioMuted,
  84. startVideoMuted,
  85. followMeEnabled,
  86. followMeRecorderEnabled,
  87. disableReactionsModeration,
  88. onStartAudioMutedToggled,
  89. onStartVideoMutedToggled,
  90. onFollowMeToggled,
  91. onFollowMeRecorderToggled,
  92. onStartReactionsMutedToggled,
  93. startReactionsMuted ]);
  94. return (
  95. <FormSection
  96. label = 'settings.playSounds'>
  97. {
  98. moderationSettings.map(({ label, state, onChange, disabled }) => (
  99. <FormRow
  100. key = { label }
  101. label = { label }>
  102. <Switch
  103. checked = { Boolean(state) }
  104. disabled = { disabled }
  105. onChange = { onChange } />
  106. </FormRow>
  107. ))
  108. }
  109. </FormSection>
  110. );
  111. };
  112. export default ModeratorSection;