1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
/** @format */
import React, { useEffect, useState } from 'react';
import Block, { Input, ModalDropDown } from './style.js';
import {useColorConfig} from "../../storage/globalColorConfig"
const CallHistoryInputDropdown = ({
inputValue,
call_history,
selectFunc,
numberSelectHistory,
setDefaultHistoryNumberHistory,
}) => {
const [modal, setModal] = useState(false);
var elem = document.getElementById('data');
const useColorConfigStore = useColorConfig((store) => store)
const selectFuncInset = (e) => {
selectFunc(e);
setModal(false);
};
useEffect(() => {
if (call_history.length) {
if (numberSelectHistory == 0 || numberSelectHistory == 'zero') {
elem.scrollTop = elem.scrollHeight;
} else {
elem.scrollTop = elem.scrollHeight - numberSelectHistory * 55;
}
}
}, [numberSelectHistory]);
useEffect(() => {
if (numberSelectHistory > 0) {
setModal(true);
} else if (numberSelectHistory == 0 || numberSelectHistory == 'zero') {
// setModal(false);
}
}, [numberSelectHistory]);
useEffect(() => {
document
.getElementById('numbersDiv')
.scrollTo(document.getElementById('numbersDiv').scrollWidth, 0);
}, [inputValue]);
console.log('input_modal: ', modal, numberSelectHistory);
document.querySelector('body').addEventListener('click', function (e) {
if (modal) setModal(false);
});
return (
<Block>
<Input
onClick={() => {
setDefaultHistoryNumberHistory();
setModal(!modal);
}}
className='nocopy'
type='text'>
<p id='numbersDiv'>{inputValue}</p>
</Input>
{Boolean(call_history.length) && (
<>
<ModalDropDown visiblevalue={modal} switchAnim={useColorConfigStore.state.switchAnim} >
<ModalDropDown.Inset id='data'>
{call_history.reverse().map((value, index) => (
<ModalDropDown.Item
key={index}
onClick={() => selectFuncInset(value.value)}
hoverBool={
call_history.length - numberSelectHistory === index
}>
{value?.value}
<p className='itemTime'>{value?.time}</p>
</ModalDropDown.Item>
))}
</ModalDropDown.Inset>
</ModalDropDown>
</>
)}
</Block>
);
};
export default CallHistoryInputDropdown;