mirror of
https://github.com/darksaid98/new-phone-who-dis.git
synced 2026-12-04 14:38:45 +00:00
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:
1 parent
4633146d40
commit
f6d7a3dbe1
42 files changed
+869
-679
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { useCallback, useEffect } from 'react';
|
||||
import { useCallback, useEffect, useRef } from 'react';
|
||||
import { useHistory } from 'react-router-dom';
|
||||
import { atom, useSetRecoilState, useRecoilValue } from 'recoil';
|
||||
import Nui from '../../nui-events/utils/Nui';
|
||||
import { usePhone } from '../../phone/hooks/usePhone';
|
||||
|
||||
const keyboardState = {
|
||||
ArrowRight: atom({
|
||||
@@ -48,6 +48,7 @@ const isKeyValid = (key) => validKeys.indexOf(key) !== -1;
|
||||
|
||||
export const useInitKeyboard = () => {
|
||||
const history = useHistory();
|
||||
const { closePhone } = usePhone();
|
||||
const getters = {
|
||||
ArrowRight: useRecoilValue(keyboardState.ArrowRight),
|
||||
ArrowLeft: useRecoilValue(keyboardState.ArrowLeft),
|
||||
@@ -58,21 +59,26 @@ export const useInitKeyboard = () => {
|
||||
Escape: useRecoilValue(keyboardState.Escape),
|
||||
};
|
||||
|
||||
const handlers = useRef(new Map());
|
||||
const setEscape = useSetRecoilState<any>(keyboardState.Escape);
|
||||
const setBackspace = useSetRecoilState(keyboardState.Backspace);
|
||||
|
||||
useEffect(
|
||||
function registerCustomKeys() {
|
||||
Object.keys(getters).forEach((g) => {
|
||||
handlers.current.set(g, getters[g]);
|
||||
});
|
||||
},
|
||||
[getters]
|
||||
);
|
||||
|
||||
useEffect(
|
||||
function handleNUIKeyboardMessage() {
|
||||
function onKeyUp(event) {
|
||||
const { key } = event;
|
||||
const callback = getters[key];
|
||||
if (
|
||||
isKeyValid(key) &&
|
||||
callback &&
|
||||
callback.handler &&
|
||||
callback.handler.call
|
||||
) {
|
||||
return callback.handler(event);
|
||||
const callback = handlers.current.get(key);
|
||||
if (isKeyValid(key) && callback && callback.call) {
|
||||
return callback(event);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -82,35 +88,22 @@ export const useInitKeyboard = () => {
|
||||
[getters]
|
||||
);
|
||||
|
||||
const escapeHandler = useCallback(() => Nui.send('phone:close'), []);
|
||||
|
||||
const backspaceHandler = useCallback((event) => {
|
||||
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
||||
// Dont anything if we are typing something :)
|
||||
return;
|
||||
}
|
||||
history.goBack();
|
||||
}, [history]);
|
||||
const backspaceHandler = useCallback(
|
||||
(event) => {
|
||||
if (['input', 'textarea'].includes(event.target.nodeName.toLowerCase())) {
|
||||
// Dont anything if we are typing something :)
|
||||
return;
|
||||
}
|
||||
history.goBack();
|
||||
},
|
||||
[history]
|
||||
);
|
||||
|
||||
useEffect(
|
||||
function registerDefaultHandlers() {
|
||||
setEscape({ handler: escapeHandler });
|
||||
setBackspace({ handler: backspaceHandler });
|
||||
handlers.current.set('Escape', () => closePhone());
|
||||
handlers.current.set('Backspace', backspaceHandler);
|
||||
},
|
||||
[setEscape, setBackspace, history, escapeHandler, backspaceHandler]
|
||||
[setEscape, setBackspace, history, backspaceHandler, closePhone]
|
||||
);
|
||||
};
|
||||
|
||||
export const useKeyboard = () => {
|
||||
const setters = {
|
||||
ArrowRight: useSetRecoilState(keyboardState.ArrowRight),
|
||||
ArrowLeft: useSetRecoilState(keyboardState.ArrowLeft),
|
||||
ArrowUp: useSetRecoilState(keyboardState.ArrowUp),
|
||||
ArrowDown: useSetRecoilState(keyboardState.ArrowDown),
|
||||
Enter: useSetRecoilState(keyboardState.Enter),
|
||||
};
|
||||
|
||||
return (key, handler) => {
|
||||
setters[key]({ handler });
|
||||
};
|
||||
};
|
||||
Reference in new issue
Block a user