Commit 73f4a102 authored by Muhammadali's avatar Muhammadali

update

parent 8c8540f1
...@@ -22,37 +22,14 @@ const ModalPhoneNumpad = ({ ...@@ -22,37 +22,14 @@ const ModalPhoneNumpad = ({
const [inputValue, setInputValue] = useState(''); const [inputValue, setInputValue] = useState('');
const [call_history, setCall_history] = useState([]); const [call_history, setCall_history] = useState([]);
const [numberSelectHistory, setNumberSelectHistory] = useState(0);
useEffect(() => { useEffect(() => {
// setCall_history(JSON.parse(localStorage.getItem('call_history')) || []); let currentCalls = localStorage.getItem('callhistory')
}, []); ? JSON.parse(localStorage.getItem('callhistory'))
: false;
// useEffect(() => { if (currentCalls) setCall_history(currentCalls);
// let call_history_storage = JSON.parse(localStorage.getItem('call_history')); }, [localStorage.getItem('callhistory'), inputValue]);
// if (call_history_storage.length !== call_history.length) {
// setCall_history(call_history_storage);
// localStorage.setItem('call_history', JSON.stringify(call_history));
// }
// }, [call_history]);
const addNumberStorage = ({ number }) => {
// let stringNumber = number.toString() || '';
// let storageNumbers =
// // (localStorage.getItem('call_history') &&
// // JSON.parse(localStorage.getItem('call_history'))) ||
// // [];
// // console.log(
// // stringNumber,
// // null === localStorage.getItem('call_history'),
// // typeof [],
// // );
// localStorage.setItem('call_history', [
// stringNumber,
// ,
// ]);
// setCall_history([number, ...call_history]);
// }
};
useEffect(() => { useEffect(() => {
if (!modalState.bool) setInputValue(''); if (!modalState.bool) setInputValue('');
}, [modalState.bool]); }, [modalState.bool]);
...@@ -90,10 +67,55 @@ const ModalPhoneNumpad = ({ ...@@ -90,10 +67,55 @@ const ModalPhoneNumpad = ({
} }
}; };
const history = ({ type }) => {
console.log('type', type);
if (phoneModal && (modalState.bool ? false : true)) {
if (
(type === 'up' && numberSelectHistory < call_history.length) ||
numberSelectHistory === 'zero'
) {
setNumberSelectHistory(
numberSelectHistory !== 'zero' ? numberSelectHistory + 1 : 0 + 1,
);
}
if (type === 'down' && numberSelectHistory > 0) {
setNumberSelectHistory(
numberSelectHistory !== 'zero' ? numberSelectHistory - 1 : 0 - 1,
);
}
}
};
useEffect(() => {
if (phoneModal && (modalState.bool ? false : true)) {
let selectedNumber;
if (numberSelectHistory == 0) {
setInputValue('');
}
selectedNumber = call_history.slice(numberSelectHistory * -1)[0]
? call_history.slice(numberSelectHistory * -1)[0]
: false;
if (numberSelectHistory === 0) {
selectedNumber = '';
setNumberSelectHistory('zero');
}
if (numberSelectHistory === 'zero') {
selectedNumber = '';
setNumberSelectHistory('zero');
}
if (selectedNumber) {
setInputValue(selectedNumber);
}
}
}, [numberSelectHistory]);
console.log('numberSelectHistory', numberSelectHistory);
document.onkeydown = function (e) { document.onkeydown = function (e) {
if (phoneModal && modalState.bool ? false : true) { if (phoneModal && modalState.bool ? false : true) {
e = e || window.event; e = e || window.event;
if (e.ctrlKey && e.keyCode === 86) { let actualKeyCode = e.keyCode;
if (e.ctrlKey && actualKeyCode === 86) {
navigator.clipboard navigator.clipboard
.readText() .readText()
.then((text) => { .then((text) => {
...@@ -109,8 +131,8 @@ const ModalPhoneNumpad = ({ ...@@ -109,8 +131,8 @@ const ModalPhoneNumpad = ({
const gameState = { const gameState = {
toggleCP: (e) => { toggleCP: (e) => {
if (phoneModal && (modalState.bool ? false : true) && e.key === 'Enter') { if (phoneModal && (modalState.bool ? false : true) && e.key === 'Enter') {
boxDialer.initialized(inputValue); // boxDialer.initialized(inputValue);
addNumberStorage({ number: inputValue }); callButton();
} else if ( } else if (
phoneModal && phoneModal &&
(modalState.bool ? false : true) && (modalState.bool ? false : true) &&
...@@ -128,12 +150,14 @@ const ModalPhoneNumpad = ({ ...@@ -128,12 +150,14 @@ const ModalPhoneNumpad = ({
(modalState.bool ? false : true) && (modalState.bool ? false : true) &&
e.key === 'Backspace' e.key === 'Backspace'
) { ) {
} } else if (
(phoneModal && (modalState.bool ? false : true) && e.keyCode == 38) ||
e.keyCode == 40
)
history({ type: e.keyCode === 38 ? 'up' : 'down' });
}, },
}; };
// ArrowDown;
// ArrowUp
const handleKeyUp = useCallback( const handleKeyUp = useCallback(
(event) => { (event) => {
gameState.toggleCP(event); gameState.toggleCP(event);
...@@ -150,11 +174,18 @@ const ModalPhoneNumpad = ({ ...@@ -150,11 +174,18 @@ const ModalPhoneNumpad = ({
}, [handleKeyUp]); }, [handleKeyUp]);
const callButton = () => { const callButton = () => {
addNumberStorage({ number: inputValue }); // inset if ----------
if (Boolean(inputValue.toString().length)) {
console.log(inputValue, 'inputValue');
let newCallsStringify = JSON.stringify([...call_history, inputValue]);
localStorage.setItem('callhistory', newCallsStringify);
}
// -------------------
if (dynamicValue === 'connected') { if (dynamicValue === 'connected') {
// let call_history = localStorage.getItem('call_history'); // let call_history = localStorage.getItem('call_history');
// console.log(call_history, 'call_history');
boxDialer.initialized(inputValue); boxDialer.initialized(inputValue);
} else { } else {
toast.error('Please wait', { toast.error('Please wait', {
......
...@@ -219,13 +219,13 @@ export class BoxDialer { ...@@ -219,13 +219,13 @@ export class BoxDialer {
let uiStates = { let uiStates = {
stack_i_new_call: stack_i_new_call:
this.callDirection === 'in' ? 'connectingIncoming' : 'connected', this.callDirection === 'in' ? 'connectingIncoming' : 'connected',
call_connected: 'connected', call_connected: 'connected',
call_m_stream_audio_remote_added: 'connected', call_m_stream_audio_remote_added: 'connected',
call_i_ao_request: 'connectingOutgoing', call_i_ao_request: 'connectingOutgoing',
stack_m_permission_accepted: stack_m_permission_accepted:
this.callDirection === 'in' ? 'incoming' : 'outgoing', this.callDirection === 'in' ? 'incoming' : 'outgoing',
}; };
return sipState && uiStates[sipState] ? uiStates[sipState] : ''; return sipState && uiStates[sipState] ? uiStates[sipState] : '';
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment