Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Player ready stuff #241

Merged
merged 4 commits into from
May 23, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 7 additions & 22 deletions phone/src/Phone.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import { Navigation } from './os/navigation-bar/components/Navigation';
import { useSimcardService } from './os/simcard/hooks/useSimcardService';
import { usePhoneService } from './os/phone/hooks/usePhoneService';
import { useApps } from './os/apps/hooks/useApps';

import { useNuiRequest } from 'fivem-nui-react-lib';
import { useContactsService } from './apps/contacts/hooks/useContactsService';
import { useTwitterService } from './apps/twitter/hooks/useTwitterService';
import { useMatchService } from './apps/match/hooks/useMatchService';
Expand Down Expand Up @@ -47,6 +47,8 @@ function Phone() {

const { addAlert } = useSnackbar();

const Nui = useNuiRequest();

// Set language from local storage
// This will only trigger on first mount & settings changes
useEffect(() => {
Expand All @@ -65,6 +67,10 @@ function Phone() {
// eslint-disable-next-line react-hooks/exhaustive-deps
}, []);

useEffect(() => {
Nui.send(PhoneEvents.UI_IS_READY);
}, [Nui]);

useKeyboardService();
usePhoneService();
useSimcardService();
Expand All @@ -81,14 +87,10 @@ function Phone() {

const { modal: callModal } = useCallModal();

//const { isPhoneReady } = usePhone();

return (
<div>
<WindowSnackbar />
<PhoneWrapper>
{/*{isPhoneReady ? (
<>*/}
<NotificationBar />
<div className="PhoneAppContainer">
<>
Expand All @@ -102,23 +104,6 @@ function Phone() {
<PhoneSnackbar />
</div>
<Navigation />
{/*</>
) : (
<Box
component={Paper}
height="100%"
width="100%"
display="flex"
flexDirection="column"
alignItems="center"
justifyContent="center"
>
<Typography paragraph variant="h6">
NPWD {t('INITIALIZING')}
</Typography>
<Typography paragraph>{t('GENERIC_WAIT')}</Typography>
</Box>
)}*/}
</PhoneWrapper>
</div>
);
Expand Down
4 changes: 0 additions & 4 deletions phone/src/os/phone/hooks/state.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,10 +10,6 @@ export const phoneState = {
key: 'resourceConfig',
default: null,
}),
/*phoneReady: atom<boolean>({
key: 'phoneReady',
default: false,
}),*/
phoneTime: atom<string>({
key: 'phoneTime',
default: null,
Expand Down
2 changes: 0 additions & 2 deletions phone/src/os/phone/hooks/usePhone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ interface IUsePhone {
export const usePhone = (): IUsePhone => {
const Nui = useNuiRequest();
const isPhoneOpen = useRecoilValue(phoneState.visibility);
//const isPhoneReady = useRecoilValue(phoneState.phoneReady);
const config = useRecoilValue(phoneState.resourceConfig);

const { removeAlerts } = useNotifications();
Expand All @@ -34,6 +33,5 @@ export const usePhone = (): IUsePhone => {
closePhone,
openPhone,
isPhoneOpen,
//isPhoneReady,
};
};
12 changes: 1 addition & 11 deletions phone/src/os/phone/hooks/usePhoneService.ts
Original file line number Diff line number Diff line change
@@ -1,22 +1,12 @@
import { useNuiEvent, useNuiRequest } from 'fivem-nui-react-lib';
import { useNuiEvent } from 'fivem-nui-react-lib';
import { useSetRecoilState } from 'recoil';
import { PhoneEvents } from '../../../../../typings/phone';
import { phoneState } from './state';
import { useEffect } from 'react';

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 setResourceConfig = useSetRecoilState(phoneState.resourceConfig);
//const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
//useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady);
useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility);
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setResourceConfig);
useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime);
Expand Down
6 changes: 6 additions & 0 deletions resources/client/cl_main.ts
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,12 @@ function fetchOnInitialize() {
sendMessage('PHONE', PhoneEvents.SET_CONFIG, config);
}

if (config.general.enableMultiChar) {
onNet(PhoneEvents.ON_INIT, () => {
fetchOnInitialize();
});
}

RegisterKeyMapping('phone', 'Open Phone', 'keyboard', 'f1');

const getCurrentGameTime = () => {
Expand Down
3 changes: 2 additions & 1 deletion resources/server/players/player.controller.ts
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import { getSource } from '../utils/miscUtils';
import PlayerService from './player.service';
import { config } from '../server';
import { config, ESX } from '../server';
import { PlayerAddData } from './player.interfaces';
import { playerLogger } from './player.utils';
import { XPlayer } from 'esx.js/@types/server';

/**
* Essentially this whole file acts as a controller layer
Expand Down
2 changes: 2 additions & 0 deletions resources/server/players/player.service.ts
Original file line number Diff line number Diff line change
Expand Up @@ -178,6 +178,8 @@ class _PlayerService {

playerLogger.info(`New NPWD Player added through event (${src}) (${identifier})`);
playerLogger.debug(player);

emitNet(PhoneEvents.ON_INIT, src);
}

/**
Expand Down