better code

Massimo Melina committed May 2, 2026 at 14:21 UTC 608c696c59c22c33467f1af961e153e75e9cc8a3
2 files changed +4 -4
admin/src/pluginOptions.ts
+3 -4
@@ -50,7 +50,6 @@ export async function showPluginOptions(row: any, maxWidth: string) {
50 const { list, setList } = useApiList('get_plugin_log', { id }, {
51 map(x) { x.ts = new Date(x.ts) }
52 })
53 - const autoScroll = useAutoScroll(list)
53 let lastDate: any
54 return h(Flex, { alignItems: 'stretch', justifyContent: 'center', flexWrap: 'wrap', flexDirection: showOptions ? undefined : 'column' },
55 h(Box, { sx: { maxWidth, minWidth: 'min-content' /*in case content requires more space (eg: reverse-proxy's table)*/ } }, children),
@@ -60,9 +59,9 @@ export async function showPluginOptions(row: any, maxWidth: string) {
59 h(Btn, { size: 'small', sx: { p: 0 }, onClick() { setList([]) } }, "Clear")
60 ),
61 h(Box, {
63 - sx: { position: 'absolute', bottom: 0, top: '31px', left: 0, right: 0, overflowY: 'auto' },
64 - ref: autoScroll,
65 - },
62 + ref: useAutoScroll(list),
63 + sx: { position: 'absolute', bottom: 0, top: '31px', left: 0, right: 0, overflowY: 'auto' }
64 + },
65 !list.length && h(Box, { sx: { p: 1 } }, "Log is empty"),
66 h(Box, {
67 sx: {
shared/react.ts
+1
@@ -209,6 +209,7 @@ export function isCtrlKey(ev: KeyboardEvent) {
209 return (ev.ctrlKey || isMac && ev.metaKey) && ev.key
210 }
211
212 +// returns a callback to be passed as ref of the element
213 export function useAutoScroll(dependency: any) {
214 const ref = useRef<HTMLElement | null>(null)
215 const lastScrollListenerRef = useRef<any>()