import { createEventSignal } from '@solid-primitives/event-listener' import { useI18n } from '@solid-primitives/i18n' import { createReconnectingWS } from '@solid-primitives/websocket' import { ColumnDef, createSolidTable, flexRender, getCoreRowModel, } from '@tanstack/solid-table' import { For, createEffect, createSignal } from 'solid-js' import { twMerge } from 'tailwind-merge' import { secret, tableSize, wsEndpointURL } from '~/signals' import { Log } from '~/types' type LogWithSeq = Log & { seq: number } export default () => { const [t] = useI18n() let seq = 0 const [search, setSearch] = createSignal('') const [logs, setLogs] = createSignal([]) const ws = createReconnectingWS(`${wsEndpointURL()}/logs?token=${secret()}`) const messageEvent = createEventSignal<{ message: WebSocketEventMap['message'] }>(ws, 'message') createEffect(() => { const data = messageEvent()?.data if (!data) { return } setLogs((logs) => [{ ...(JSON.parse(data) as Log), seq }, ...logs].slice(0, 100), ) seq++ }) const columns: ColumnDef[] = [ { accessorKey: 'Sequence', accessorFn: (row) => row.seq, }, { accessorKey: 'Type', accessorFn: (row) => row.type, }, { accessorKey: 'Payload', accessorFn: (row) => row.payload, }, ] const table = createSolidTable({ get data() { return search() ? logs().filter((log) => log.payload.toLowerCase().includes(search().toLowerCase()), ) : logs() }, columns, getCoreRowModel: getCoreRowModel(), }) return (
setSearch(e.target.value)} />
{(headerGroup) => ( {(header) => ( )} )} {(row) => ( {(cell) => ( )} )}
{header.isPlaceholder ? null : flexRender( header.column.columnDef.header, header.getContext(), )}
{flexRender( cell.column.columnDef.cell, cell.getContext(), )}
) }