/* eslint-disable @typescript-eslint/naming-convention */ import { memo, useCallback, useEffect, useState } from 'react' import { Button, useClipboard } from '@janhq/joi' import { useAtomValue } from 'jotai' import { FolderIcon, CheckIcon, CopyIcon } from 'lucide-react' import { twMerge } from 'tailwind-merge' import { useLogs } from '@/hooks/useLogs' import { usePath } from '@/hooks/usePath' import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' type ServerLogsProps = { limit?: number; withCopy?: boolean } const ServerLogs = (props: ServerLogsProps) => { const { limit = 0, withCopy } = props const { getLogs } = useLogs() const serverEnabled = useAtomValue(serverEnabledAtom) const [logs, setLogs] = useState([]) const updateLogs = useCallback( () => getLogs('app').then((log) => { if (typeof log?.split === 'function') { setLogs( log.split(/\r?\n|\r|\n/g).filter((e) => e.includes('[SERVER]::')) ) } }), // eslint-disable-next-line react-hooks/exhaustive-deps [] ) useEffect(() => { if (serverEnabled) { updateLogs() } }, [serverEnabled, updateLogs]) useEffect(() => { updateLogs() // Log polling interval const intervalId = setInterval(() => { updateLogs() }, window.core?.api?.pollingInterval ?? 1200) // clean up interval return () => clearInterval(intervalId) }, [updateLogs]) const { onRevealInFinder } = usePath() const clipboard = useClipboard({ timeout: 1000 }) return (
{withCopy && (
)}
{logs.length > 0 ? ( {logs.slice(-limit).map((log, i) => { return (

{log}

) })}
) : (

Empty logs

)}
) } export default memo(ServerLogs)