Update LogsTerminal.tsx

This commit is contained in:
Hristo Nedelkov 2023-11-28 12:18:58 +02:00
parent 920d70d230
commit 8c5397ac11

View File

@ -32,19 +32,12 @@ const fetchMoreData = () => {
const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => { const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => {
const [data, setData] = useState<DataType[]>([]) const [data, setData] = useState<DataType[]>([])
const [isScrolling, setIsScrolling] = useState(false)
const [loadedIndexes, setLoadedIndexes] = useState<{ [key: number]: boolean }>({}) const [loadedIndexes, setLoadedIndexes] = useState<{ [key: number]: boolean }>({})
const listRef = useRef<List | null>(null) const listRef = useRef<List | null>(null)
const [shouldAutoScroll, setShouldAutoScroll] = useState(true) const [shouldAutoScroll, setShouldAutoScroll] = useState(true)
useEffect(() => {
const interval = setInterval(() => {
//addNewLog()
}, 3000)
return () => clearInterval(interval)
}, [isScrolling])
useEffect(() => { useEffect(() => {
if (shouldAutoScroll) { if (shouldAutoScroll) {
@ -62,7 +55,6 @@ const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => {
const isItemLoaded = (index: number) => !!loadedIndexes[index] const isItemLoaded = (index: number) => !!loadedIndexes[index]
const addNewLog = () => { const addNewLog = () => {
if (!isScrolling) {
const newLog: DataType = { const newLog: DataType = {
option: `--new-option-${data.length + 1}`, option: `--new-option-${data.length + 1}`,
description: `New log entry ${data.length + 1} ${Math.random()}`, description: `New log entry ${data.length + 1} ${Math.random()}`,
@ -75,7 +67,6 @@ const LogsTerminal = ({ windowWidth, timestamps }: LogsTerminalProps) => {
listRef.current?.scrollToItem(data.length, 'end') listRef.current?.scrollToItem(data.length, 'end')
} }
} }
}
const handleScroll = ({ scrollTop, scrollHeight, clientHeight }: any) => { const handleScroll = ({ scrollTop, scrollHeight, clientHeight }: any) => {
const isAtBottom = scrollTop + clientHeight >= scrollHeight const isAtBottom = scrollTop + clientHeight >= scrollHeight