2021-09-10 11:05:16 +00:00
|
|
|
import { useCallback, useState } from 'react';
|
|
|
|
import { useDispatch } from 'react-redux';
|
|
|
|
|
2023-02-21 09:26:04 +00:00
|
|
|
import { handleLobbyChatInitialized } from '../chat/actions.web';
|
2022-11-23 09:12:26 +00:00
|
|
|
import { approveKnockingParticipant, rejectKnockingParticipant } from '../lobby/actions.web';
|
2021-09-10 11:05:16 +00:00
|
|
|
|
2022-10-20 09:11:27 +00:00
|
|
|
interface IDrawerParticipant {
|
2022-10-13 08:26:28 +00:00
|
|
|
displayName?: string;
|
|
|
|
participantID: string;
|
|
|
|
}
|
|
|
|
|
2021-09-10 11:05:16 +00:00
|
|
|
/**
|
|
|
|
* Hook used to create admit/reject lobby actions.
|
|
|
|
*
|
|
|
|
* @param {Object} participant - The participant for which the actions are created.
|
|
|
|
* @param {Function} closeDrawer - Callback for closing the drawer.
|
|
|
|
* @returns {Array<Function>}
|
|
|
|
*/
|
2022-10-20 09:11:27 +00:00
|
|
|
export function useLobbyActions(participant?: IDrawerParticipant | null, closeDrawer?: Function) {
|
2021-09-10 11:05:16 +00:00
|
|
|
const dispatch = useDispatch();
|
|
|
|
|
|
|
|
return [
|
|
|
|
useCallback(e => {
|
|
|
|
e.stopPropagation();
|
2022-11-23 09:12:26 +00:00
|
|
|
dispatch(approveKnockingParticipant(participant?.participantID ?? ''));
|
2022-10-13 08:26:28 +00:00
|
|
|
closeDrawer?.();
|
2021-09-10 11:05:16 +00:00
|
|
|
}, [ dispatch, closeDrawer ]),
|
|
|
|
|
|
|
|
useCallback(() => {
|
2022-11-23 09:12:26 +00:00
|
|
|
dispatch(rejectKnockingParticipant(participant?.participantID ?? ''));
|
2022-10-13 08:26:28 +00:00
|
|
|
closeDrawer?.();
|
2022-03-03 17:29:38 +00:00
|
|
|
}, [ dispatch, closeDrawer ]),
|
|
|
|
|
|
|
|
useCallback(() => {
|
2022-10-13 08:26:28 +00:00
|
|
|
dispatch(handleLobbyChatInitialized(participant?.participantID ?? ''));
|
2022-03-03 17:29:38 +00:00
|
|
|
}, [ dispatch ])
|
2021-09-10 11:05:16 +00:00
|
|
|
];
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hook used to create actions & state for opening a drawer.
|
|
|
|
*
|
|
|
|
* @returns {Array<any>}
|
|
|
|
*/
|
2022-10-13 08:26:28 +00:00
|
|
|
export function useParticipantDrawer(): [
|
2022-10-20 09:11:27 +00:00
|
|
|
IDrawerParticipant | null,
|
2022-10-13 08:26:28 +00:00
|
|
|
() => void,
|
2022-10-20 09:11:27 +00:00
|
|
|
(p: IDrawerParticipant | null) => void ] {
|
|
|
|
const [ drawerParticipant, openDrawerForParticipant ] = useState<IDrawerParticipant | null>(null);
|
2021-09-10 11:05:16 +00:00
|
|
|
const closeDrawer = useCallback(() => {
|
|
|
|
openDrawerForParticipant(null);
|
2022-10-13 08:26:28 +00:00
|
|
|
}, []);
|
2021-09-10 11:05:16 +00:00
|
|
|
|
|
|
|
return [
|
|
|
|
drawerParticipant,
|
|
|
|
closeDrawer,
|
|
|
|
openDrawerForParticipant
|
|
|
|
];
|
|
|
|
}
|