Fix fetch on initialize (fixing notifications too) (#202)

* Fix fetch on initialize (fixing notifications too)

* Add multiline support to messages input field
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-04-08 10:53:12 -03:00
1 parent 62038aa5fe
commit e70c540ce8
4 files changed
+31 -6

No files matched your search

@@ -43,6 +43,8 @@ const MessageInput = ({ messageGroupId, onAddImageClick }: IProps) => {
<Box display="flex"> <Box display="flex">
<Box pl={1} flexGrow={1}> <Box pl={1} flexGrow={1}>
<TextField <TextField
multiline
aria-multiline="true"
fullWidth fullWidth
inputProps={{ style: { fontSize: '1.3em' } }} inputProps={{ style: { fontSize: '1.3em' } }}
value={message} value={message}
+10 -1
View File
@@ -1,8 +1,17 @@
import { useNuiEvent } from 'fivem-nui-react-lib'; import { useNuiEvent, useNuiRequest } from 'fivem-nui-react-lib';
import { useEffect } from 'react';
import { useSetRecoilState } from 'recoil'; import { useSetRecoilState } from 'recoil';
import { PhoneEvents } from '../../../../../typings/phone';
import { phoneState } from './state'; import { phoneState } from './state';
export const usePhoneService = () => { export const usePhoneService = () => {
const { send } = useNuiRequest();
// Let client know UI is ready to accept events
useEffect(() => {
send(PhoneEvents.UI_IS_READY);
}, [send]);
const setVisibility = useSetRecoilState(phoneState.visibility); const setVisibility = useSetRecoilState(phoneState.visibility);
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady); const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
+18 -5
View File
@@ -13,7 +13,8 @@ import { CallEvents } from '../../typings/call';
import { MatchEvents } from '../../typings/match'; import { MatchEvents } from '../../typings/match';
let isPhoneOpen = false; let isPhoneOpen = false;
let isPhoneReady = false; let isPlayerReady = false;
let isUiReady = false;
/* * * * * * * * * * * * * /* * * * * * * * * * * * *
* *
@@ -21,11 +22,10 @@ let isPhoneReady = false;
* *
* * * * * * * * * * * * */ * * * * * * * * * * * * */
function fetchOnInitialize() { function fetchOnInitialize() {
isPhoneReady = true;
emitNet(ContactEvents.GET_CONTACTS); emitNet(ContactEvents.GET_CONTACTS);
emitNet(MessageEvents.FETCH_MESSAGE_GROUPS); emitNet(MessageEvents.FETCH_MESSAGE_GROUPS);
emitNet(TwitterEvents.GET_OR_CREATE_PROFILE); emitNet(TwitterEvents.GET_OR_CREATE_PROFILE);
sendMessage('PHONE', 'setPhoneReady', isPhoneReady); sendMessage('PHONE', 'setPhoneReady', true);
sendMessage('PHONE', 'phoneConfig', config); sendMessage('PHONE', 'phoneConfig', config);
} }
@@ -97,7 +97,6 @@ RegisterCommand(
* * * * * * * * * * * * */ * * * * * * * * * * * * */
async function Phone(): Promise<void> { async function Phone(): Promise<void> {
fetchOnInitialize();
if (config.PhoneAsItem) { if (config.PhoneAsItem) {
// TODO: Do promise callback here // TODO: Do promise callback here
// const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem') // const hasPhoneItem = await emitNetPromise('phone:hasPhoneItem')
@@ -111,7 +110,12 @@ async function Phone(): Promise<void> {
} }
// triggerd when the player is ready // triggerd when the player is ready
onNet(PhoneEvents.PLAYER_IS_READY, fetchOnInitialize); onNet(PhoneEvents.PLAYER_IS_READY, () => {
isPlayerReady = true;
if (isUiReady) {
fetchOnInitialize();
}
});
AddEventHandler('onResourceStop', function (resource: string) { AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) { if (resource === GetCurrentResourceName()) {
@@ -126,6 +130,15 @@ onNet('phone:sendCredentials', (number: string) => {
sendMessage('SIMCARD', 'setNumber', number); sendMessage('SIMCARD', 'setNumber', number);
}); });
RegisterNuiCallbackType(PhoneEvents.UI_IS_READY);
on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => {
isUiReady = true;
if (isPlayerReady) {
fetchOnInitialize();
}
cb();
});
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP // DO NOT CHANGE THIS EITHER, PLEASE - CHIP
// ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ // ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ
+1
View File
@@ -1,6 +1,7 @@
export const PHONE_NUMBER_REGEX = /^([0-9]{3}-[0-9]{4})|([0-9]{7})$/; export const PHONE_NUMBER_REGEX = /^([0-9]{3}-[0-9]{4})|([0-9]{7})$/;
export enum PhoneEvents { export enum PhoneEvents {
UI_IS_READY = 'npwd:uiIsReady',
PLAYER_IS_READY = 'npwd:playerIsReady', PLAYER_IS_READY = 'npwd:playerIsReady',
OPEN_APP_CONTACTS = 'npwd:app:CONTACTS', OPEN_APP_CONTACTS = 'npwd:app:CONTACTS',
OPEN_APP_BANK = 'npwd:app:BANK', OPEN_APP_BANK = 'npwd:app:BANK',