Some minor code quality improvements

master
WolverinDEV 2021-07-11 14:21:16 +02:00
parent f7fe3162c3
commit 547a5224b5
3 changed files with 14 additions and 13 deletions

View File

@ -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<HTMLDivElement>();
const scrollOffset = useRef<number | "bottom">("bottom");
const [ , setRevision ] = useState(0);
const [ logs, setLogs ] = useDependentState<LogMessage[] | "loading">(() => {
events.fire_react("query_log");
return "loading";
}, [ handlerId ]);
const [ revision, setRevision ] = useState(0);
const refContainer = useRef<HTMLDivElement>();
const scrollOffset = useRef<number | "bottom">("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 = () => {

View File

@ -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) {

View File

@ -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 (
<div className={cssStyle.expendArrow} onClick={() => 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 (
<div className={joinClassList(cssStyle.container, streamingCount === 0 && cssStyle.hidden, expanded && cssStyle.expended)}>
{props.children}