import type React from 'react'; import { AnimatePresence, m } from 'framer-motion'; import { FiArrowRight, FiPaperclip } from 'react-icons/fi'; import { useAppSelector } from '@app/hooks/useAppSelector'; import { Protobuf, Types } from '@meshtastic/meshtasticjs'; export const Logs = (): JSX.Element => { const logs = useAppSelector((state) => state.meshtastic.logs); const darkMode = useAppSelector((state) => state.app.darkMode); type lookupType = { [key: number]: string }; const emitterLookup: lookupType = { [Types.Emitter.sendPacket]: 'text-blue-500', [Types.Emitter.sendText]: 'text-blue-500', [Types.Emitter.sendPacket]: 'text-blue-500', [Types.Emitter.sendRaw]: 'text-blue-500', [Types.Emitter.setPreferences]: 'text-blue-500', [Types.Emitter.confirmSetPreferences]: 'text-blue-500', [Types.Emitter.setOwner]: 'text-blue-500', [Types.Emitter.setChannel]: 'text-blue-500', [Types.Emitter.confirmSetChannel]: 'text-blue-500', [Types.Emitter.deleteChannel]: 'text-blue-500', [Types.Emitter.getChannel]: 'text-blue-500', [Types.Emitter.getAllChannels]: 'text-blue-500', [Types.Emitter.getPreferences]: 'text-blue-500', [Types.Emitter.getOwner]: 'text-blue-500', [Types.Emitter.configure]: 'text-blue-500', [Types.Emitter.handleFromRadio]: 'text-blue-500', [Types.Emitter.handleMeshPacket]: 'text-blue-500', [Types.Emitter.connect]: 'text-blue-500', [Types.Emitter.ping]: 'text-blue-500', [Types.Emitter.readFromRadio]: 'text-blue-500', [Types.Emitter.writeToRadio]: 'text-blue-500', [Types.Emitter.setDebugMode]: 'text-blue-500', }; const levelLookup: lookupType = { [Protobuf.LogRecord_Level.UNSET]: 'text-green-500', [Protobuf.LogRecord_Level.CRITICAL]: 'text-purple-500', [Protobuf.LogRecord_Level.ERROR]: 'text-red-500', [Protobuf.LogRecord_Level.WARNING]: 'text-orange-500', [Protobuf.LogRecord_Level.INFO]: 'text-blue-500', [Protobuf.LogRecord_Level.DEBUG]: 'text-neutral-500', [Protobuf.LogRecord_Level.TRACE]: 'text-slate-500', }; return (
{/* \/ flex flex-col gap-2 */} {logs.length === 0 && (
)}
{logs.map((log, index) => (
{log.date .toLocaleString(undefined, { year: 'numeric', month: '2-digit', day: '2-digit', hour: '2-digit', minute: '2-digit', second: '2-digit', }) .replaceAll('/', '-') .replace(',', '')}
[{Types.EmitterScope[log.scope]}.{Types.Emitter[log.emitter]}]
[{Protobuf.LogRecord_Level[log.level]}]{/* */} ))}
{log.message}
); }; const Wrapper = ({ className, children, }: { className?: string; children: React.ReactNode; }): JSX.Element => ( {children} );