Files
new-phone-who-dis/phone/src/os/call/hooks/useCall.ts
T
Taso e6deff23da tweak(phone/dialer): Cleanup & type safety for state
Renamed some types to better represent their data
2021-04-01 13:40:37 -04:00

38 lines
918 B
TypeScript

import { useRecoilState } from 'recoil';
import { ActiveCall } from '../../../../../typings/call';
import Nui from '../../nui-events/utils/Nui';
import { callerState } from './state';
import { CallEvents } from '../../../../../typings/call';
interface CallHook {
call: ActiveCall;
setCall: (details: any) => void;
acceptCall(): void;
rejectCall(): void;
endCall(): void;
}
export const useCall = (): CallHook => {
const [call, setCall] = useRecoilState(callerState.currentCall);
const acceptCall = () => {
Nui.send(CallEvents.ACCEPT_CALL, {
transmitterNumber: call.transmitter,
});
};
const rejectCall = () => {
Nui.send(CallEvents.REJECTED, {
phoneNumber: call.transmitter,
});
};
const endCall = () => {
Nui.send(CallEvents.END_CALL, {
transmitterNumber: call.transmitter,
});
};
return { call, setCall, acceptCall, rejectCall, endCall };
};