fix(phone): only listen to UI Ready

This commit is contained in:
Christopher committed 2021-05-21 00:35:05 +02:00
1 parent 2411c39b95
commit fb32aaef15
6 files changed
+26 -47

No files matched your search

+16 -16
View File
@@ -81,28 +81,28 @@ function Phone() {
const { modal: callModal } = useCallModal(); const { modal: callModal } = useCallModal();
const { isPhoneReady } = usePhone(); //const { isPhoneReady } = usePhone();
return ( return (
<div> <div>
<WindowSnackbar /> <WindowSnackbar />
<PhoneWrapper> <PhoneWrapper>
{isPhoneReady ? ( {/*{isPhoneReady ? (
<>*/}
<NotificationBar />
<div className="PhoneAppContainer">
<> <>
<NotificationBar /> <Route exact path="/" component={HomeApp} />
<div className="PhoneAppContainer"> {callModal && <Route exact path="/call" component={CallModal} />}
<> {apps.map((App) => (
<Route exact path="/" component={HomeApp} /> <App.Route key={App.id} />
{callModal && <Route exact path="/call" component={CallModal} />} ))}
{apps.map((App) => (
<App.Route key={App.id} />
))}
</>
<NotificationAlert />
<PhoneSnackbar />
</div>
<Navigation />
</> </>
<NotificationAlert />
<PhoneSnackbar />
</div>
<Navigation />
{/*</>
) : ( ) : (
<Box <Box
component={Paper} component={Paper}
@@ -118,7 +118,7 @@ function Phone() {
</Typography> </Typography>
<Typography paragraph>{t('GENERIC_WAIT')}</Typography> <Typography paragraph>{t('GENERIC_WAIT')}</Typography>
</Box> </Box>
)} )}*/}
</PhoneWrapper> </PhoneWrapper>
</div> </div>
); );
+2 -2
View File
@@ -10,10 +10,10 @@ export const phoneState = {
key: 'resourceConfig', key: 'resourceConfig',
default: null, default: null,
}), }),
phoneReady: atom<boolean>({ /*phoneReady: atom<boolean>({
key: 'phoneReady', key: 'phoneReady',
default: false, default: false,
}), }),*/
phoneTime: atom<string>({ phoneTime: atom<string>({
key: 'phoneTime', key: 'phoneTime',
default: null, default: null,
+3 -3
View File
@@ -10,13 +10,13 @@ interface IUsePhone {
openPhone(): void; openPhone(): void;
closePhone(): void; closePhone(): void;
isPhoneOpen: boolean; isPhoneOpen: boolean;
isPhoneReady: boolean; //isPhoneReady: boolean;
} }
export const usePhone = (): IUsePhone => { export const usePhone = (): IUsePhone => {
const Nui = useNuiRequest(); const Nui = useNuiRequest();
const isPhoneOpen = useRecoilValue(phoneState.visibility); const isPhoneOpen = useRecoilValue(phoneState.visibility);
const isPhoneReady = useRecoilValue(phoneState.phoneReady); //const isPhoneReady = useRecoilValue(phoneState.phoneReady);
const config = useRecoilValue(phoneState.resourceConfig); const config = useRecoilValue(phoneState.resourceConfig);
const { removeAlerts } = useNotifications(); const { removeAlerts } = useNotifications();
@@ -34,6 +34,6 @@ export const usePhone = (): IUsePhone => {
closePhone, closePhone,
openPhone, openPhone,
isPhoneOpen, isPhoneOpen,
isPhoneReady, //isPhoneReady,
}; };
}; };
+2 -2
View File
@@ -14,9 +14,9 @@ export const usePhoneService = () => {
const setVisibility = useSetRecoilState(phoneState.visibility); const setVisibility = useSetRecoilState(phoneState.visibility);
const setResourceConfig = useSetRecoilState(phoneState.resourceConfig); const setResourceConfig = useSetRecoilState(phoneState.resourceConfig);
const setPhoneReady = useSetRecoilState(phoneState.phoneReady); //const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
const setPhoneTime = useSetRecoilState(phoneState.phoneTime); const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady); //useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady);
useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility); useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility);
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setResourceConfig); useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setResourceConfig);
useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime); useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime);
+3 -17
View File
@@ -12,8 +12,6 @@ import { CallEvents } from '../../typings/call';
import { config } from './client'; import { config } from './client';
let isPhoneOpen = false; let isPhoneOpen = false;
let isPlayerReady = false;
let isUiReady = false;
/* * * * * * * * * * * * * /* * * * * * * * * * * * *
* *
@@ -24,7 +22,6 @@ function fetchOnInitialize() {
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', PhoneEvents.SET_PHONE_READY, true);
sendMessage('PHONE', PhoneEvents.SET_CONFIG, config); sendMessage('PHONE', PhoneEvents.SET_CONFIG, config);
} }
@@ -113,14 +110,10 @@ async function Phone(): Promise<void> {
} }
} }
// Set the global depending on the response from event onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
onNet(PhoneEvents.PLAYER_IS_READY, (ready: boolean) => { sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number);
isPlayerReady = ready;
}); });
onNet(PhoneEvents.SEND_CREDENTIALS, (number: string) => {
sendMessage('SIMCARD', PhoneEvents.SET_NUMBER, number)
})
AddEventHandler('onResourceStop', function (resource: string) { AddEventHandler('onResourceStop', function (resource: string) {
if (resource === GetCurrentResourceName()) { if (resource === GetCurrentResourceName()) {
sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false); sendMessage('PHONE', PhoneEvents.SET_VISIBILITY, false);
@@ -132,15 +125,8 @@ AddEventHandler('onResourceStop', function (resource: string) {
RegisterNuiCallbackType(PhoneEvents.UI_IS_READY); RegisterNuiCallbackType(PhoneEvents.UI_IS_READY);
on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => { on(`__cfx_nui:${PhoneEvents.UI_IS_READY}`, (_data: any, cb: Function) => {
isUiReady = true;
if (isPlayerReady) {
fetchOnInitialize();
}
cb();
});
onNet(PhoneEvents.ON_INIT, () => {
fetchOnInitialize(); fetchOnInitialize();
cb();
}); });
// DO NOT CHANGE THIS EITHER, PLEASE - CHIP // DO NOT CHANGE THIS EITHER, PLEASE - CHIP
@@ -129,10 +129,6 @@ class _PlayerService {
playerLogger.info('NPWD Player Loaded!'); playerLogger.info('NPWD Player Loaded!');
playerLogger.debug(newPlayer); playerLogger.debug(newPlayer);
// Emit to client that player is ready
console.log('init baby', pSource);
emitNet(PhoneEvents.PLAYER_IS_READY, pSource, true);
} }
/** /**
@@ -182,9 +178,6 @@ class _PlayerService {
playerLogger.info(`New NPWD Player added through event (${src}) (${identifier})`); playerLogger.info(`New NPWD Player added through event (${src}) (${identifier})`);
playerLogger.debug(player); playerLogger.debug(player);
// Emit to client that player is ready
emitNet(PhoneEvents.PLAYER_IS_READY, src, true);
} }
/** /**