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.

ModeratorSection.tsx 3.9KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  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. followMeEnabled,
  19. followMeRecorderEnabled,
  20. startAudioMuted,
  21. startVideoMuted,
  22. startReactionsMuted
  23. } = useSelector((state: IReduxState) => getModeratorTabProps(state));
  24. const { disableReactionsModeration } = useSelector((state: IReduxState) => state['features/base/config']);
  25. const onStartAudioMutedToggled = useCallback((enabled?: boolean) => {
  26. dispatch(setStartMutedPolicy(
  27. Boolean(enabled), Boolean(startVideoMuted)));
  28. }, [ startVideoMuted, dispatch, setStartMutedPolicy ]);
  29. const onStartVideoMutedToggled = useCallback((enabled?: boolean) => {
  30. dispatch(setStartMutedPolicy(
  31. Boolean(startAudioMuted), Boolean(enabled)));
  32. }, [ startAudioMuted, dispatch, setStartMutedPolicy ]);
  33. const onFollowMeToggled = useCallback((enabled?: boolean) => {
  34. dispatch(setFollowMe(Boolean(enabled)));
  35. }, [ dispatch, setFollowMe ]);
  36. const onFollowMeRecorderToggled = useCallback((enabled?: boolean) => {
  37. dispatch(setFollowMeRecorder(Boolean(enabled)));
  38. }, [ dispatch, setFollowMeRecorder ]);
  39. const onStartReactionsMutedToggled = useCallback((enabled?: boolean) => {
  40. dispatch(setStartReactionsMuted(Boolean(enabled), true));
  41. dispatch(updateSettings({ soundsReactions: enabled }));
  42. }, [ dispatch, updateSettings, setStartReactionsMuted ]);
  43. const moderationSettings = useMemo(() => {
  44. const moderation = [
  45. {
  46. label: 'settings.startAudioMuted',
  47. state: startAudioMuted,
  48. onChange: onStartAudioMutedToggled
  49. },
  50. {
  51. label: 'settings.startVideoMuted',
  52. state: startVideoMuted,
  53. onChange: onStartVideoMutedToggled
  54. },
  55. {
  56. label: 'settings.followMe',
  57. state: followMeEnabled,
  58. onChange: onFollowMeToggled
  59. },
  60. {
  61. label: 'settings.followMeRecorder',
  62. state: followMeRecorderEnabled,
  63. onChange: onFollowMeRecorderToggled
  64. },
  65. {
  66. label: 'settings.startReactionsMuted',
  67. state: startReactionsMuted,
  68. onChange: onStartReactionsMutedToggled
  69. }
  70. ];
  71. if (disableReactionsModeration) {
  72. moderation.pop();
  73. }
  74. return moderation;
  75. }, [ startAudioMuted,
  76. startVideoMuted,
  77. followMeEnabled,
  78. followMeRecorderEnabled,
  79. disableReactionsModeration,
  80. onStartAudioMutedToggled,
  81. onStartVideoMutedToggled,
  82. onFollowMeToggled,
  83. onFollowMeRecorderToggled,
  84. onStartReactionsMutedToggled,
  85. startReactionsMuted ]);
  86. return (
  87. <FormSection
  88. label = 'settings.playSounds'>
  89. {
  90. moderationSettings.map(({ label, state, onChange }) => (
  91. <FormRow
  92. key = { label }
  93. label = { label }>
  94. <Switch
  95. checked = { Boolean(state) }
  96. onChange = { onChange } />
  97. </FormRow>
  98. ))
  99. }
  100. </FormSection>
  101. );
  102. };
  103. export default ModeratorSection;