Feature/floating notifications calling and twitter (#112)

* Add floating notifications :O

* Add phone notifications and refactor calling ui

* This is unsafe

* Fix controls null check

* Remove go to alert

* Fix phone stuck after call

* Remove lazy mount for Phone

* Fix open/close cl_main

* Use effect for notification visibility

* Remove all alerts when phone closes

* Avoid re-render useNuiEvent

* It works now :c
This commit is contained in:
J Francisco Rader authored and GitHub committed 2021-02-23 13:19:10 -05:00
1 parent 4633146d40
commit f6d7a3dbe1
42 files changed
+869 -679

No files matched your search

+10 -13
View File
@@ -16,17 +16,16 @@ interface IOptions {
* @param options Any options to pass to the addEventListener
**/
export const useNuiEvent = (
const defaultOptions = {};
export const useNuiEvent = <S = Record<string, unknown>>(
app: string,
method: string,
handler: Function,
options: IOptions = {},
currentState?: Record<string, unknown>
currentState?: S,
options: IOptions = defaultOptions
) => {
const savedHandler: MutableRefObject<any> = useRef();
// Destructure passed options
const { capture, passive, once } = options;
// When handler value changes set mutable ref to handler val
useEffect(() => {
@@ -44,15 +43,13 @@ export const useNuiEvent = (
data: event.data,
level: 1,
});
const newData = currentState ? { ...currentState, ...data } : data
savedHandler.current(newData)
const newData = currentState ? { ...currentState, ...data } : data;
savedHandler.current(newData);
}
};
// Why are destructing then restructuring option data?
const opts = { capture, passive, once };
window.addEventListener(eventName, eventListener, opts);
window.addEventListener(eventName, eventListener, options);
// Remove Event Listener on component cleanup
return () => window.removeEventListener(eventName, eventListener, opts);
}, [app, method, capture, passive, once, currentState]);
return () => window.removeEventListener(eventName, eventListener, options);
}, [app, method, currentState, options]);
};