diff --git a/phone/src/Phone.tsx b/phone/src/Phone.tsx index 7fe22ab..62db9b2 100644 --- a/phone/src/Phone.tsx +++ b/phone/src/Phone.tsx @@ -4,7 +4,7 @@ import './i18n'; import { Route } from 'react-router-dom'; import { CallModal } from './os/call/components/CallModal'; import { HomeApp } from './apps/home/components/Home'; -import { Slide } from '@material-ui/core'; +import { Box, Paper, Slide, Typography } from '@material-ui/core'; import { useKeyboardService } from './os/keyboard/hooks/useKeyboardService'; import { NotificationBar } from './os/notifications/components/NotificationBar'; import { Navigation } from './os/navigation-bar/components/Navigation'; @@ -29,8 +29,11 @@ import { PhoneSnackbar } from './ui/components/PhoneSnackbar'; import { NotificationAlert } from './os/notifications/components/NotificationAlert'; import { useCallModal } from './os/call/hooks/useCallModal'; import WindowSnackbar from './ui/components/WindowSnackbar'; +import { usePhone } from './os/phone/hooks/usePhone'; +import { useTranslation } from 'react-i18next'; function Phone() { + const { t } = useTranslation(); const { apps } = useApps(); const [settings] = useSettings(); @@ -51,6 +54,7 @@ function Phone() { const { modal: callModal } = useCallModal(); const { bottom, visibility } = usePhoneVisibility(); + const { isPhoneReady } = usePhone(); return (
@@ -79,21 +83,38 @@ function Phone() { backgroundImage: `url(./media/backgrounds/${settings.wallpaper.value})`, }} > - <> - -
- <> - - {callModal && } - {apps.map((App) => ( - - ))} - - - -
- - + {isPhoneReady ? ( + <> + +
+ <> + + {callModal && } + {apps.map((App) => ( + + ))} + + + +
+ + + ) : ( + + + NPWD {t('INITIALIZING')} + + {t('GENERIC_WAIT')} + + )}
@@ -110,4 +131,9 @@ InjectDebugData([ method: 'setVisibility', data: true, }, + { + app: 'PHONE', + method: 'setPhoneReady', + data: true, + }, ]); diff --git a/phone/src/apps/messages/hooks/useMessageService.ts b/phone/src/apps/messages/hooks/useMessageService.ts index b3babe2..60c37e0 100644 --- a/phone/src/apps/messages/hooks/useMessageService.ts +++ b/phone/src/apps/messages/hooks/useMessageService.ts @@ -4,8 +4,7 @@ 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, useEffect } from 'react'; -import Nui from '../../../os/nui-events/utils/Nui'; +import { useCallback } from 'react'; export const useMessagesService = () => { const setMessageGroups = useSetRecoilState(messageState.messageGroups); @@ -15,10 +14,6 @@ export const useMessagesService = () => { const { setNotification } = useMessageNotifications(); const { t } = useTranslation(); - useEffect(() => { - Nui.send('phone:fetchMessageGroups'); - }, []); - const handleAddAlert = useCallback( ({ message, type }: IAlert) => { addAlert({ diff --git a/phone/src/locale/en.json b/phone/src/locale/en.json index 599974f..c2c8892 100644 --- a/phone/src/locale/en.json +++ b/phone/src/locale/en.json @@ -4,6 +4,7 @@ "DATE_TIME_FORMAT": "MM/DD/YYYY hh:mm A", "COMING_SOON": "Coming soon...", + "INITIALIZING": "Initializing", "APPS_DIALER": "Phone", "APPS_CONTACTS": "Contacts", @@ -119,6 +120,7 @@ "APPS_MARKETPLACE_CREATE_LISTING_SUCCESS": "Successfully created a new listing", "APPS_MARKETPALCE_CREATE_LISTING_FAILED": "Failed to create a new listing", + "GENERIC_WAIT": "Please wait...", "GENERIC_SAVE": "Save", "GENERIC_UPDATE": "Update", "GENERIC_DELETE": "Delete", diff --git a/phone/src/os/phone/hooks/state.ts b/phone/src/os/phone/hooks/state.ts index 1dc0ad3..d12133c 100644 --- a/phone/src/os/phone/hooks/state.ts +++ b/phone/src/os/phone/hooks/state.ts @@ -9,8 +9,8 @@ export const phoneState = { key: 'phoneConfig', default: undefined, }), - forceUpdateState: atom({ - key: 'fuckingupdate', - default: 0, + phoneReady: atom({ + key: 'phoneReady', + default: false, }), }; diff --git a/phone/src/os/phone/hooks/usePhone.ts b/phone/src/os/phone/hooks/usePhone.ts index 595af6e..b09525f 100644 --- a/phone/src/os/phone/hooks/usePhone.ts +++ b/phone/src/os/phone/hooks/usePhone.ts @@ -10,10 +10,12 @@ interface IUsePhone { openPhone(): void; closePhone(): void; isPhoneOpen: boolean; + isPhoneReady: boolean; } export const usePhone = (): IUsePhone => { const isPhoneOpen = useRecoilValue(phoneState.visibility); + const isPhoneReady = useRecoilValue(phoneState.phoneReady); const { removeAlerts } = useNotifications(); @@ -25,5 +27,5 @@ export const usePhone = (): IUsePhone => { Nui.send('phone:open'); }; - return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen }; + return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen, isPhoneReady }; }; diff --git a/phone/src/os/phone/hooks/usePhoneService.ts b/phone/src/os/phone/hooks/usePhoneService.ts index de43871..957b153 100644 --- a/phone/src/os/phone/hooks/usePhoneService.ts +++ b/phone/src/os/phone/hooks/usePhoneService.ts @@ -5,6 +5,8 @@ import { useNuiEvent } from '../../nui-events/hooks/useNuiEvent'; export const usePhoneService = () => { const setVisibility = useSetRecoilState(phoneState.visibility); const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig); + const setPhoneReady = useSetRecoilState(phoneState.phoneReady); useNuiEvent('PHONE', 'setVisibility', setVisibility); + useNuiEvent('PHONE', 'setPhoneReady', setPhoneReady); useNuiEvent('PHONE', 'phoneConfig', setPhoneConfig); }; diff --git a/resources/client/cl_main.ts b/resources/client/cl_main.ts index e24a467..9186c52 100644 --- a/resources/client/cl_main.ts +++ b/resources/client/cl_main.ts @@ -3,6 +3,26 @@ import events from '../utils/events'; import { phoneCloseAnim, phoneOpenAnim, removePhoneProp } from './functions'; let isPhoneOpen = false; +let isPhoneReady = false; + +/* * * * * * * * * * * * * + * + * Phone initialize data + * + * * * * * * * * * * * * */ +function fetchOnInitialize() { + isPhoneReady = true; + emitNet(events.CONTACTS_GET_CONTACTS); + emitNet(events.MESSAGES_FETCH_MESSAGE_GROUPS); + emitNet(events.TWITTER_GET_OR_CREATE_PROFILE); + SendNuiMessage( + JSON.stringify({ + app: 'PHONE', + method: 'setPhoneReady', + data: true, + }), + ); +} RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1'); @@ -90,6 +110,8 @@ async function Phone(): Promise { } } +onNet('esx:playerLoaded', fetchOnInitialize); + AddEventHandler('onResourceStop', function (resource: string) { if (resource === GetCurrentResourceName()) { SendNuiMessage( @@ -116,17 +138,13 @@ onNet('phone:sendCredentials', (number: string) => { }); // DO NOT CHANGE THIS EITHER, PLEASE - CHIP +// ^ AND WHAT ARE YOU GOING TO DO HUH? - KIDZ /* * * * * * * * * * * * * * * NUI Service Callback Registration * * * * * * * * * * * * * */ - -function fetchOnInitialize() { - emitNet(events.CONTACTS_GET_CONTACTS); -} - RegisterNuiCallbackType(events.OPEN_APP_LISTINGS); on(`__cfx_nui:${events.OPEN_APP_LISTINGS}`, (data: any, cb: Function) => { emitNet(events.SELLOUT_FETCH_LISTING);