cleanup(phone/gen): Added NUI event enums for phone events

This commit is contained in:
Taso committed 2021-04-01 13:42:48 -04:00
1 parent e6deff23da
commit 9610891a04
7 files changed
+29 -18

No files matched your search

+3 -2
View File
@@ -33,6 +33,7 @@ import WindowSnackbar from './ui/components/WindowSnackbar';
import { usePhone } from './os/phone/hooks/usePhone';
import { useTranslation } from 'react-i18next';
import { useSnackbar } from './ui/hooks/useSnackbar';
import { PhoneEvents } from '../../typings/phone';
function Phone() {
const { t, i18n } = useTranslation();
@@ -154,12 +155,12 @@ export default Phone;
InjectDebugData([
{
app: 'PHONE',
method: 'setVisibility',
method: PhoneEvents.SET_VISIBILITY,
data: true,
},
{
app: 'PHONE',
method: 'setPhoneReady',
method: PhoneEvents.SET_PHONE_READY,
data: true,
},
]);
+5 -4
View File
@@ -1,14 +1,15 @@
import { useSetRecoilState } from 'recoil';
import { phoneState } from './state';
import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent';
import { PhoneEvents } from '../../../../../typings/phone';
export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
useNuiEvent('PHONE', 'setVisibility', setVisibility);
useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady);
useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig);
useNuiEvent('PHONE', 'setTime', setPhoneTime);
useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility);
useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady);
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setPhoneConfig);
useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime);
};
@@ -3,6 +3,7 @@ import { useSetRecoilState } from 'recoil';
import { simcardState } from './state';
import { useSimcard } from './useSimcard';
import InjectDebugData from '../../debug/InjectDebugData';
import { PhoneEvents } from '../../../../../typings/phone';
InjectDebugData([
{
@@ -14,6 +15,6 @@ InjectDebugData([
export const useSimcardService = () => {
const setNumber = useSetRecoilState(simcardState.number);
useNuiEvent('SIMCARD', 'setNumber', setNumber);
useNuiEvent('SIMCARD', PhoneEvents.SET_NUMBER, setNumber);
return useSimcard();
};
+8 -8
View File
@@ -25,8 +25,8 @@ function fetchOnInitialize() {
emitNet(ContactEvents.GET_CONTACTS);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS);
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE);
sendMessage('PHONE', 'setPhoneReady', isPhoneReady);
sendMessage('PHONE', 'phoneConfig', config);
sendMessage('PHONE', PhoneEvents.SET_PHONE_READY, isPhoneReady);
sendMessage('PHONE', PhoneEvents.SET_CONFIG, config);
}
RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');
@@ -55,14 +55,14 @@ const showPhone = async (): Promise<void> => {
await phoneOpenAnim(); // Animation starts before the phone is open
emitNet('phone:getCredentials');
SetCursorLocation(0.9, 0.922); //Experimental
sendMessage('PHONE', 'setVisibility', true);
sendMessage('PHONE', 'setTime', time);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
sendMessage('PHONE', PhoneEvents.SET_TIME, time);
SetNuiFocus(true, true);
};
const hidePhone = async (): Promise<void> => {
isPhoneOpen = false;
sendMessage('PHONE', 'setVisibility', false);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
await phoneCloseAnim();
SetNuiFocus(false, false);
};
@@ -115,15 +115,15 @@ onNet(PhoneEvents.PLAYER_IS_READY, fetchOnInitialize);
AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) {
sendMessage('PHONE', 'setVisibility', false);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
SetNuiFocus(false, false);
removePhoneProp(); //Deletes the phone incase it was attached.
ClearPedTasks(PlayerPedId()); //Leave here until launch as it'll fix any stuck animations.
}
});
onNet('phone:sendCredentials', (number: string) => {
sendMessage('SIMCARD', 'setNumber', number);
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP
+3 -2
View File
@@ -1,6 +1,7 @@
import { PhotoEvents } from '../../typings/photo';
import { Delay } from '../utils/fivem';
import { sendMessage, sendCameraEvent } from '../utils/messages';
import { PhoneEvents } from '../../typings/phone';
const SCREENSHOT_BASIC_TOKEN = GetConvar('SCREENSHOT_BASIC_TOKEN', 'none');
const exp = (global as any).exports;
@@ -9,12 +10,12 @@ let inCameraMode = false;
function closePhoneTemp() {
SetNuiFocus(false, false);
sendMessage('PHONE', 'setVisibility', false);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
}
function openPhoneTemp() {
SetNuiFocus(true, true);
sendMessage('PHONE', 'setVisibility', true);
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, true);
}
function CellFrontCamActivate(activate: boolean) {
+2 -1
View File
@@ -1,6 +1,7 @@
import { pool } from './db';
import { getIdentifier, getSource } from './functions';
import { mainLogger } from './sv_logger';
import { PhoneEvents } from '../../typings/phone';
interface Credentials {
phone_number: string;
@@ -19,7 +20,7 @@ onNet('phone:getCredentials', async () => {
try {
const identifier = getIdentifier(_source);
const number = await getCredentials(identifier);
emitNet('phone:sendCredentials', _source, number);
emitNet(PhoneEvents.SEND_CREDENTIALS, _source, number);
} catch (e) {
mainLogger.error(`Failed to get a number, ${e.message}`, {
source: _source,
+6
View File
@@ -11,5 +11,11 @@ export enum PhoneEvents {
OPEN_PHONE = 'npwd:open',
CLOSE_PHONE = 'npwd:close',
SET_ALERT = 'npwd:setAlert',
SET_VISIBILITY = 'npwd:setVisibility',
SET_NOTIFICATION = 'npwd:setNotification',
SET_NUMBER = 'npwd:setNumber',
SET_PHONE_READY = 'npwd:phoneReady',
SET_CONFIG = 'npwd:setPhoneConfig',
SET_TIME = 'npwd:setGameTime',
SEND_CREDENTIALS = 'npwd:sendCredentials',
}