/* eslint-disable @typescript-eslint/naming-convention */ import { useEffect, useState } from 'react' import React from 'react' import { Button } from '@janhq/uikit' import { useAtomValue } from 'jotai' import { CopyIcon, CheckIcon } from 'lucide-react' import { useClipboard } from '@/hooks/useClipboard' import { useLogs } from '@/hooks/useLogs' import { serverEnabledAtom } from '@/helpers/atoms/LocalServer.atom' type ServerLogsProps = { limit?: number; withCopy?: boolean } const ServerLogs = (props: ServerLogsProps) => { const { limit = 0 } = props const { getLogs } = useLogs() const serverEnabled = useAtomValue(serverEnabledAtom) const [logs, setLogs] = useState([]) const clipboard = useClipboard({ timeout: 1000 }) useEffect(() => { getLogs('server').then((log) => { if (typeof log?.split === 'function') { setLogs(log.split(/\r?\n|\r|\n/g)) } }) // eslint-disable-next-line react-hooks/exhaustive-deps }, [logs, serverEnabled]) return ( <>
{logs.slice(-limit).map((log, i) => {
return (
{log}
)
})}
Empty logs