From 547a5224b59f4c8878bbd6915e2fdac339786371 Mon Sep 17 00:00:00 2001 From: WolverinDEV Date: Sun, 11 Jul 2021 14:21:16 +0200 Subject: [PATCH] Some minor code quality improvements --- shared/js/ui/frames/log/Renderer.tsx | 19 ++++++++++--------- shared/js/ui/frames/side/HeaderRenderer.tsx | 2 +- shared/js/ui/frames/video/Renderer.tsx | 6 +++--- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/shared/js/ui/frames/log/Renderer.tsx b/shared/js/ui/frames/log/Renderer.tsx index 57d64cd4..b0b675cf 100644 --- a/shared/js/ui/frames/log/Renderer.tsx +++ b/shared/js/ui/frames/log/Renderer.tsx @@ -43,22 +43,23 @@ const LogEntryRenderer = React.memo((props: { entry: LogMessage }) => { ); }); -const ServerLogRenderer = () => { +const ServerLogRenderer = (props: { backlog?: number }) => { + const backlog = typeof props.backlog === "number" ? props.backlog : 100; const handlerId = useContext(HandlerIdContext); const events = useContext(EventsContext); + + const refContainer = useRef(); + const scrollOffset = useRef("bottom"); + + const [ , setRevision ] = useState(0); const [ logs, setLogs ] = useDependentState(() => { events.fire_react("query_log"); return "loading"; }, [ handlerId ]); - const [ revision, setRevision ] = useState(0); - - const refContainer = useRef(); - const scrollOffset = useRef("bottom"); - events.reactUse("notify_log", event => { const logs = event.events.slice(0); - logs.splice(0, Math.max(0, logs.length - 100)); + logs.splice(0, Math.max(0, logs.length - backlog)); logs.sort((a, b) => a.timestamp - b.timestamp); setLogs(logs); }); @@ -69,9 +70,9 @@ const ServerLogRenderer = () => { } logs.push(event.event); - logs.splice(0, Math.max(0, logs.length - 100)); + logs.splice(0, Math.max(0, logs.length - backlog)); logs.sort((a, b) => a.timestamp - b.timestamp); - setRevision(revision + 1); + setRevision(performance.now()); }); const fixScroll = () => { diff --git a/shared/js/ui/frames/side/HeaderRenderer.tsx b/shared/js/ui/frames/side/HeaderRenderer.tsx index 51fac7a5..cfed951f 100644 --- a/shared/js/ui/frames/side/HeaderRenderer.tsx +++ b/shared/js/ui/frames/side/HeaderRenderer.tsx @@ -116,7 +116,7 @@ const BlockPing = () => { return undefined; }); - events.reactUse("notify_ping", event => setPingInfo(event.ping)); + events.reactUse("notify_ping", event => setPingInfo(event.ping), undefined, [ ]); let value, title; if(!pingInfo) { diff --git a/shared/js/ui/frames/video/Renderer.tsx b/shared/js/ui/frames/video/Renderer.tsx index 6658156e..1cfc373f 100644 --- a/shared/js/ui/frames/video/Renderer.tsx +++ b/shared/js/ui/frames/video/Renderer.tsx @@ -41,7 +41,7 @@ const ExpendArrow = React.memo(() => { return false; }); - events.reactUse("notify_expended", event => setExpended(event.expended), undefined, [ setExpended ]); + events.reactUse("notify_expended", event => setExpended(event.expended), undefined, []); return (
events.fire("action_toggle_expended", { expended: !expended })}> @@ -776,8 +776,8 @@ const VisibilityHandler = React.memo((props: { return false; }) - events.reactUse("notify_videos", event => setStreamingCount(event.videoActiveCount)); - events.reactUse("notify_expended", event => setExpanded(event.expended)); + events.reactUse("notify_videos", event => setStreamingCount(event.videoActiveCount), []); + events.reactUse("notify_expended", event => setExpanded(event.expended), []); return (
{props.children}