mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 22:16:40 +00:00
Merge branch 'master' into feat/calling-lua-ts
This commit is contained in:
commit
853184dba6
3 files changed
+37
-16
No files matched your search
@@ -1,5 +1,6 @@
|
|||||||
import { useEffect, useRef } from 'react';
|
import { MutableRefObject, useEffect, useRef } from 'react';
|
||||||
import { eventNameFactory } from '../utils/nuiUtils';
|
import { eventNameFactory } from '../utils/nuiUtils';
|
||||||
|
import DebugLog from '../../debug/LogDebugEvents';
|
||||||
|
|
||||||
interface IOptions {
|
interface IOptions {
|
||||||
capture?: boolean;
|
capture?: boolean;
|
||||||
@@ -7,30 +8,48 @@ interface IOptions {
|
|||||||
once?: boolean;
|
once?: boolean;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* A hook that manage events listeners for receiving data from the NUI
|
||||||
|
* @param app The app name in which this hoook is used
|
||||||
|
* @param method The specific `method` field that should be listened for.
|
||||||
|
* @param handler The callback function that will handle data relayed by this hook
|
||||||
|
* @param options Any options to pass to the addEventListener
|
||||||
|
**/
|
||||||
|
|
||||||
export const useNuiEvent = (
|
export const useNuiEvent = (
|
||||||
app: any,
|
app: string,
|
||||||
method: any,
|
method: string,
|
||||||
handler: any,
|
handler: Function,
|
||||||
options: IOptions = {}
|
options: IOptions = {}
|
||||||
) => {
|
) => {
|
||||||
const savedHandler: any = useRef();
|
const savedHandler: MutableRefObject<any> = useRef();
|
||||||
|
// Destructure passed options
|
||||||
const { capture, passive, once } = options;
|
const { capture, passive, once } = options;
|
||||||
|
|
||||||
|
// When handler value changes set mutable ref to handler val
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
savedHandler.current = handler;
|
savedHandler.current = handler;
|
||||||
}, [handler]);
|
}, [handler]);
|
||||||
|
|
||||||
|
// Will run every rerender
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const eventName = eventNameFactory(app, method);
|
const eventName = eventNameFactory(app, method);
|
||||||
const eventListener = (event: any) => {
|
const eventListener = (event) => {
|
||||||
if (savedHandler.current && savedHandler.current.call) {
|
if (savedHandler.current && savedHandler.current.call) {
|
||||||
const { data } = event;
|
const { data } = event;
|
||||||
console.log(eventName, data);
|
DebugLog({
|
||||||
|
action: `NUI Data Received (${eventName})`,
|
||||||
|
data: event.data,
|
||||||
|
level: 1,
|
||||||
|
});
|
||||||
savedHandler.current(data);
|
savedHandler.current(data);
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
// Why are destructing then restructuring option data?
|
||||||
const opts = { capture, passive, once };
|
const opts = { capture, passive, once };
|
||||||
|
|
||||||
window.addEventListener(eventName, eventListener, opts);
|
window.addEventListener(eventName, eventListener, opts);
|
||||||
|
// Remove Event Listener on component cleanup
|
||||||
return () => window.removeEventListener(eventName, eventListener, opts);
|
return () => window.removeEventListener(eventName, eventListener, opts);
|
||||||
}, [app, method, capture, passive, once]);
|
}, [app, method, capture, passive, once]);
|
||||||
};
|
};
|
||||||
@@ -4,7 +4,7 @@ import { AppContentTypes } from '../interface/InterfaceUI';
|
|||||||
|
|
||||||
const useStyles = makeStyles(() => ({
|
const useStyles = makeStyles(() => ({
|
||||||
wrapper: {
|
wrapper: {
|
||||||
height: '70vh', // NOTE: Taso: Hacky change temp, this should be done automatically tbh. Will refactor at some point
|
flex: 1,
|
||||||
overflow: 'auto',
|
overflow: 'auto',
|
||||||
},
|
},
|
||||||
box: {
|
box: {
|
||||||
@@ -39,7 +39,7 @@ export const AppContent = ({
|
|||||||
className={classes.backdrop}
|
className={classes.backdrop}
|
||||||
open={backdrop || false}
|
open={backdrop || false}
|
||||||
onClick={onClickBackdrop}
|
onClick={onClickBackdrop}
|
||||||
></Backdrop>
|
/>
|
||||||
{children}
|
{children}
|
||||||
</Paper>
|
</Paper>
|
||||||
</Box>
|
</Box>
|
||||||
|
|||||||
@@ -1,13 +1,15 @@
|
|||||||
|
import { CSSProperties } from 'react';
|
||||||
|
|
||||||
export interface AppContentTypes {
|
export interface AppContentTypes {
|
||||||
children: any;
|
children?: JSX.Element | JSX.Element[];
|
||||||
style?: any;
|
style?: CSSProperties;
|
||||||
backdrop?: any;
|
backdrop?: boolean;
|
||||||
onClickBackdrop?: any;
|
onClickBackdrop?: (...args: any[]) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
export interface AppWrapperTypes {
|
export interface AppWrapperTypes {
|
||||||
id?: string;
|
id?: string;
|
||||||
children: any;
|
children?: JSX.Element | JSX.Element[];
|
||||||
style?: any;
|
style?: CSSProperties;
|
||||||
handleClickAway?: any;
|
handleClickAway?: (...args: any[]) => void;
|
||||||
}
|
}
|
||||||
Reference in new issue
Block a user