mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
tweak(config): Config var & send as event method
config -> ResourceConfig for readability and the resource config in NUI is now being referenced consistently from state so it can be referenced at runtime and not compile time. Also removes the need to copy the config before using `cp`
This commit is contained in:
1 parent
8ce6ec7559
commit
dd3eac4a0e
18 files changed
+66
-89
No files matched your search
@@ -1,13 +1,13 @@
|
||||
import { atom } from 'recoil';
|
||||
import { IServerConfig } from '../../../../../typings/config';
|
||||
import { ResourceConfig } from '../../../../../typings/config';
|
||||
|
||||
export const phoneState = {
|
||||
visibility: atom<boolean>({
|
||||
key: 'phoneVisibility',
|
||||
default: false,
|
||||
}),
|
||||
phoneConfig: atom<IServerConfig>({
|
||||
key: 'phoneConfig',
|
||||
resourceConfig: atom<ResourceConfig>({
|
||||
key: 'resourceConfig',
|
||||
default: null,
|
||||
}),
|
||||
phoneReady: atom<boolean>({
|
||||
|
||||
@@ -1,13 +1,12 @@
|
||||
import { useRecoilValue } from 'recoil';
|
||||
import { IServerConfig } from '../../../../../typings/config';
|
||||
import ServerConfig from '../../../config.autogen.json';
|
||||
import { ResourceConfig } from '../../../../../typings/config';
|
||||
import { useNotifications } from '../../notifications/hooks/useNotifications';
|
||||
import { useNuiRequest } from 'fivem-nui-react-lib';
|
||||
import { phoneState } from './state';
|
||||
import { PhoneEvents } from '../../../../../typings/phone';
|
||||
|
||||
interface IUsePhone {
|
||||
config?: IServerConfig;
|
||||
ResourceConfig?: ResourceConfig;
|
||||
openPhone(): void;
|
||||
closePhone(): void;
|
||||
isPhoneOpen: boolean;
|
||||
@@ -18,6 +17,7 @@ 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();
|
||||
|
||||
@@ -29,5 +29,11 @@ export const usePhone = (): IUsePhone => {
|
||||
Nui.send(PhoneEvents.OPEN_PHONE);
|
||||
};
|
||||
|
||||
return { config: ServerConfig as any, closePhone, openPhone, isPhoneOpen, isPhoneReady };
|
||||
return {
|
||||
ResourceConfig: config as ResourceConfig,
|
||||
closePhone,
|
||||
openPhone,
|
||||
isPhoneOpen,
|
||||
isPhoneReady,
|
||||
};
|
||||
};
|
||||
@@ -13,11 +13,11 @@ export const usePhoneService = () => {
|
||||
}, [send]);
|
||||
|
||||
const setVisibility = useSetRecoilState(phoneState.visibility);
|
||||
const setPhoneConfig = useSetRecoilState(phoneState.phoneConfig);
|
||||
const setResourceConfig = useSetRecoilState(phoneState.resourceConfig);
|
||||
const setPhoneReady = useSetRecoilState(phoneState.phoneReady);
|
||||
const setPhoneTime = useSetRecoilState(phoneState.phoneTime);
|
||||
useNuiEvent('PHONE', PhoneEvents.SET_VISIBILITY, setVisibility);
|
||||
useNuiEvent('PHONE', PhoneEvents.SET_PHONE_READY, setPhoneReady);
|
||||
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setPhoneConfig);
|
||||
useNuiEvent('PHONE', PhoneEvents.SET_CONFIG, setResourceConfig);
|
||||
useNuiEvent('PHONE', PhoneEvents.SET_TIME, setPhoneTime);
|
||||
};
|
||||
Reference in new issue
Block a user