您最多选择25个主题 主题必须以字母或数字开头,可以包含连字符 (-),并且长度不得超过35个字符

hooks.js 1.6KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. import { useCallback, useState } from 'react';
  2. import { useDispatch } from 'react-redux';
  3. import { handleLobbyChatInitialized } from '../chat/actions.any';
  4. import { approveKnockingParticipant, rejectKnockingParticipant } from '../lobby/actions';
  5. /**
  6. * Hook used to create admit/reject lobby actions.
  7. *
  8. * @param {Object} participant - The participant for which the actions are created.
  9. * @param {Function} closeDrawer - Callback for closing the drawer.
  10. * @returns {Array<Function>}
  11. */
  12. export function useLobbyActions(participant, closeDrawer) {
  13. const dispatch = useDispatch();
  14. return [
  15. useCallback(e => {
  16. e.stopPropagation();
  17. dispatch(approveKnockingParticipant(participant && participant.participantID));
  18. closeDrawer && closeDrawer();
  19. }, [ dispatch, closeDrawer ]),
  20. useCallback(() => {
  21. dispatch(rejectKnockingParticipant(participant && participant.participantID));
  22. closeDrawer && closeDrawer();
  23. }, [ dispatch, closeDrawer ]),
  24. useCallback(() => {
  25. dispatch(handleLobbyChatInitialized(participant && participant.participantID));
  26. }, [ dispatch ])
  27. ];
  28. }
  29. /**
  30. * Hook used to create actions & state for opening a drawer.
  31. *
  32. * @returns {Array<any>}
  33. */
  34. export function useParticipantDrawer() {
  35. const [ drawerParticipant, openDrawerForParticipant ] = useState(null);
  36. const closeDrawer = useCallback(() => {
  37. openDrawerForParticipant(null);
  38. });
  39. return [
  40. drawerParticipant,
  41. closeDrawer,
  42. openDrawerForParticipant
  43. ];
  44. }