mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-03 14:38:45 +00:00
tweak(phone): update old NuiCallbacks with new wrapper func
Also switches old Nui.send() calls with fetchNui on focus input control
This commit is contained in:
1 parent
fc939885a8
commit
d648b21d3b
4 files changed
+23
-53
No files matched your search
@@ -1,24 +1,18 @@
|
||||
import React, { useCallback } from 'react';
|
||||
import React from 'react';
|
||||
import MUITextField from '@material-ui/core/TextField';
|
||||
import MUIInputBase, { InputBaseProps } from '@material-ui/core/InputBase';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { PhoneEvents } from '../../../../typings/phone';
|
||||
import { TextFieldProps } from '@material-ui/core/TextField/TextField';
|
||||
import { fetchNui } from '../../utils/fetchNui';
|
||||
import { isEnvBrowser } from '../../utils/misc';
|
||||
import { noop } from '../../../../resources/utils/misc';
|
||||
|
||||
const useToggleFocus = () => {
|
||||
const Nui = useNuiRequest();
|
||||
return useCallback(
|
||||
(keepGameFocus: boolean) => {
|
||||
Nui.send(PhoneEvents.TOGGLE_KEYS, {
|
||||
keepGameFocus,
|
||||
});
|
||||
},
|
||||
[Nui],
|
||||
);
|
||||
};
|
||||
const toggleKeys = (keepGameFocus: boolean) =>
|
||||
fetchNui(PhoneEvents.TOGGLE_KEYS, {
|
||||
keepGameFocus,
|
||||
}).catch((e) => (isEnvBrowser() ? noop : console.error(e)));
|
||||
|
||||
export const TextField: React.FC<TextFieldProps> = (props) => {
|
||||
const toggleKeys = useToggleFocus();
|
||||
return (
|
||||
<MUITextField
|
||||
{...props}
|
||||
@@ -39,7 +33,6 @@ export const TextField: React.FC<TextFieldProps> = (props) => {
|
||||
};
|
||||
|
||||
export const InputBase: React.FC<InputBaseProps> = (props) => {
|
||||
const toggleKeys = useToggleFocus();
|
||||
return (
|
||||
<MUIInputBase
|
||||
{...props}
|
||||
|
||||
+13
-28
@@ -2,9 +2,6 @@ import { sendMessage } from '../utils/messages';
|
||||
import { PhoneEvents } from '../../typings/phone';
|
||||
import { TwitterEvents } from '../../typings/twitter';
|
||||
import { MessageEvents } from '../../typings/messages';
|
||||
import { BankEvents } from '../../typings/bank';
|
||||
import { PhotoEvents } from '../../typings/photo';
|
||||
import { CallEvents } from '../../typings/call';
|
||||
import { config } from './client';
|
||||
import { animationService } from './animations/animation.controller';
|
||||
import { RegisterNuiCB } from './cl_utils';
|
||||
@@ -122,7 +119,7 @@ onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
|
||||
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
|
||||
});
|
||||
|
||||
AddEventHandler('onResourceStop', function (resource: string) {
|
||||
on('onResourceStop', (resource: string) => {
|
||||
if (resource === GetCurrentResourceName()) {
|
||||
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
|
||||
SetNuiFocus(false, false);
|
||||
@@ -140,34 +137,22 @@ AddEventHandler('onResourceStop', function (resource: string) {
|
||||
* NUI Service Callback Registration
|
||||
*
|
||||
* * * * * * * * * * * * */
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_BANK);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_BANK}`, (data: any, cb: Function) => {
|
||||
emitNet(BankEvents.FETCH_TRANSACTIONS);
|
||||
emitNet(BankEvents.GET_CREDENTIALS);
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.OPEN_APP_DAILER);
|
||||
on(`__cfx_nui:${PhoneEvents.OPEN_APP_DAILER}`, (data: any, cb: Function) => {
|
||||
emitNet(CallEvents.FETCH_CALLS);
|
||||
cb();
|
||||
});
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.CLOSE_PHONE);
|
||||
on(`__cfx_nui:${PhoneEvents.CLOSE_PHONE}`, async (data: any, cb: Function) => {
|
||||
RegisterNuiCB<void>(PhoneEvents.CLOSE_PHONE, async (_, cb) => {
|
||||
await hidePhone();
|
||||
cb();
|
||||
}); // Called for when the phone is closed via the UI.
|
||||
|
||||
RegisterNuiCallbackType(PhoneEvents.TOGGLE_KEYS);
|
||||
on(`__cfx_nui:${PhoneEvents.TOGGLE_KEYS}`, async (data: any, cb: Function) => {
|
||||
if (isPhoneOpen) {
|
||||
SetNuiFocusKeepInput(data.keepGameFocus);
|
||||
}
|
||||
cb();
|
||||
});
|
||||
|
||||
// NOTE: This probably has an edge case when phone is closed for some reason
|
||||
// and we need to toggle keep input off
|
||||
RegisterNuiCB<{ keepGameFocus: boolean }>(
|
||||
PhoneEvents.TOGGLE_KEYS,
|
||||
async ({ keepGameFocus }, cb) => {
|
||||
// We will only
|
||||
if (isPhoneOpen) SetNuiFocusKeepInput(keepGameFocus);
|
||||
cb({});
|
||||
},
|
||||
);
|
||||
|
||||
// setTick(async () => {
|
||||
// while (config.SwimDestroy) {
|
||||
// await Delay(config.RunRate * 1000);
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
// eslint-disable-next-line @typescript-eslint/no-empty-function
|
||||
export const noop = () => {};
|
||||
@@ -1,19 +1,9 @@
|
||||
export const PHONE_NUMBER_REGEX = /^([0-9]{3}-[0-9]{4})|([0-9]{7})$/;
|
||||
|
||||
export enum PhoneEvents {
|
||||
UI_IS_READY = 'npwd:uiIsReady',
|
||||
PLAYER_IS_READY = 'npwd:playerIsReady',
|
||||
OPEN_APP_CONTACTS = 'npwd:app:CONTACTS',
|
||||
OPEN_APP_BANK = 'npwd:app:BANK',
|
||||
OPEN_APP_NOTES = 'npwd:app:NOTES',
|
||||
OPEN_APP_LISTINGS = 'npwd:app:MARKETPLACE',
|
||||
OPEN_APP_CAMERA = 'npwd:app:CAMERA',
|
||||
OPEN_APP_DAILER = 'npwd:app:DIALER',
|
||||
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',
|
||||
|
||||
Reference in new issue
Block a user