mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 06:28:51 +00:00
* Set phone ready before sending any init events + Show initializing phone message if not ready yet * Send phone ready to nui
34 lines
1.4 KiB
TypeScript
34 lines
1.4 KiB
TypeScript
import { useSetRecoilState } from 'recoil';
|
|
import { messageState } from './state';
|
|
import { useNuiEvent } from '../../../os/nui-events/hooks/useNuiEvent';
|
|
import { IAlert, useSnackbar } from '../../../ui/hooks/useSnackbar';
|
|
import { useTranslation } from 'react-i18next';
|
|
import { useMessageNotifications } from './useMessageNotifications';
|
|
import { useCallback } from 'react';
|
|
|
|
export const useMessagesService = () => {
|
|
const setMessageGroups = useSetRecoilState(messageState.messageGroups);
|
|
const setMessages = useSetRecoilState(messageState.messages);
|
|
const setCreateMessageGroupResult = useSetRecoilState(messageState.createMessageGroupResult);
|
|
const { addAlert } = useSnackbar();
|
|
const { setNotification } = useMessageNotifications();
|
|
const { t } = useTranslation();
|
|
|
|
const handleAddAlert = useCallback(
|
|
({ message, type }: IAlert) => {
|
|
addAlert({
|
|
message: t(`APPS_${message}`),
|
|
type,
|
|
});
|
|
},
|
|
[addAlert, t],
|
|
);
|
|
|
|
useNuiEvent('MESSAGES', 'phone:fetchMessageGroupsSuccess', setMessageGroups);
|
|
useNuiEvent('MESSAGES', 'phone:fetchMessagesSuccess', setMessages);
|
|
useNuiEvent('MESSAGES', 'phone:createMessageGroupSuccess', setCreateMessageGroupResult);
|
|
useNuiEvent('MESSAGES', 'phone:createMessageGroupFailed', setCreateMessageGroupResult);
|
|
useNuiEvent('MESSAGES', 'createMessagesBroadcast', setNotification);
|
|
useNuiEvent('MESSAGES', 'phone:setMessagesAlert', handleAddAlert);
|
|
};
|