From 776d8f8daf0b2232a5b25020f14c4062b74761a7 Mon Sep 17 00:00:00 2001 From: YetAnotherZephyruso <176294927+YetAnotherZephyruso@users.noreply.github.com> Date: Wed, 24 Jul 2024 11:51:25 +0800 Subject: [PATCH] feat: logs pause (#855) --- src/pages/Logs.tsx | 40 +++++++++++----------------------------- src/signals/logs.ts | 28 ++++++++++++++++++++++++++++ src/types/index.d.ts | 2 ++ 3 files changed, 41 insertions(+), 29 deletions(-) create mode 100644 src/signals/logs.ts diff --git a/src/pages/Logs.tsx b/src/pages/Logs.tsx index 8b8e6bd..523a66a 100644 --- a/src/pages/Logs.tsx +++ b/src/pages/Logs.tsx @@ -1,5 +1,7 @@ import { makePersisted } from '@solid-primitives/storage' import { + IconPlayerPause, + IconPlayerPlay, IconSettings, IconSortAscending, IconSortDescending, @@ -19,16 +21,9 @@ import { twMerge } from 'tailwind-merge' import { Button, LogsSettingsModal } from '~/components' import { LOG_LEVEL } from '~/constants' import { useI18n } from '~/i18n' -import { - endpoint, - logsTableSize, - tableSizeClassName, - useWsRequest, -} from '~/signals' -import { logLevel, logMaxRows } from '~/signals/config' -import { Log } from '~/types' - -type LogWithSeq = Log & { seq: number } +import { endpoint, logsTableSize, tableSizeClassName } from '~/signals' +import { useLogs } from '~/signals/logs' +import { LogWithSeq } from '~/types' const fuzzyFilter: FilterFn = (row, columnId, value, addMeta) => { // Rank the item @@ -53,27 +48,9 @@ export default () => { } let logsSettingsModalRef: HTMLDialogElement | undefined - const [t] = useI18n() - - let seq = 1 - const [logs, setLogs] = createSignal([]) - - const logsData = useWsRequest('logs', { level: logLevel() }) - - createEffect(() => { - const data = logsData() - - if (!data) { - return - } - - setLogs((logs) => [{ ...data, seq }, ...logs].slice(0, logMaxRows())) - - seq++ - }) - const [globalFilter, setGlobalFilter] = createSignal('') + const { logs, paused, setPaused } = useLogs() const [sorting, setSorting] = makePersisted(createSignal([]), { name: 'logsTableSorting', @@ -152,6 +129,11 @@ export default () => { onInput={(e) => setGlobalFilter(e.target.value)} /> +