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.

hooks.js 1.4KB

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