@samitouri / QOSami-HFS / commits / 11b4f1fa

fix: admin/logs: block-ip button didn't reflect changes to block rules until you refreshed the browser

Massimo Melina committed Mar 18, 2025 at 20:10 UTC 11b4f1fa2b97beaaab6899ae793ac7ed6b40e9d1
2 files changed +7 -2
admin/src/blockIp.ts
+1 -1
@@ -6,7 +6,7 @@ import { Block } from '@mui/icons-material'
6 import { useBatch } from '@hfs/shared'
7
8 export function BlockIpBtn({ ip, comment, ...rest }: { ip: string, comment: string } & Partial<IconBtnProps>) {
9 - const { data, refresh } = useBatch(isIpBlocked, ip, { delay: 100 })
9 + const { data, refresh } = useBatch(isIpBlocked, ip, { delay: 100, expireAfter: 5_000 })
10 return h(IconBtn, {
11 icon: Block,
12 title: "Block IP",
shared/react.ts
+6 -1
@@ -52,7 +52,7 @@ export function useRequestRender() {
52 export function useBatch<Job=unknown,Result=unknown>(
53 worker: Falsy | ((jobs: Job[]) => Promise<Result[]>),
54 job: undefined | Job,
55 - { delay=0 }={}
55 + { delay=0, expireAfter=0 }={}
56 ) {
57 interface Env {
58 batch: Set<Job>
@@ -78,6 +78,11 @@ export function useBatch<Job=unknown,Result=unknown>(
78 jobs.forEach((job, i) =>
79 env.cache.set(job, res[i] ?? null) )
80 }).finally(resolve)
81 + if (expireAfter)
82 + setTimeout(() => {
83 + for (const job of jobs)
84 + env.cache.delete(job)
85 + }, expireAfter)
86 }
87 finally {
88 env.waiter = undefined