better code
Massimo Melina committed
Mar 23, 2023 at 21:18 UTC
eaecb2f91ea9cc546ab5d6a5ae93758e41685408
1 file changed
+9
-4
frontend/src/useFetchList.ts
+9
-4
@@ -12,7 +12,7 @@ import { ERRORS } from './misc'
12
import { t } from './i18n'
13
import { useNavigate } from 'react-router-dom'
14
15
-const API = 'file_list'
15
+const RELOADER_PROP = Symbol('reloader')
16
17
export default function useFetchList() {
18
const snap = useSnapState()
@@ -35,7 +35,13 @@ export default function useFetchList() {
35
return
36
}
37
38
- const baseParams = { path: encodeURI(desiredPath), search, sse:true, omit:'c' }
38
+ const baseParams = {
39
+ path: encodeURI(desiredPath),
40
+ search,
41
+ sse: true,
42
+ omit: 'c',
43
+ [RELOADER_PROP]: snap.listReloader, // symbol, so it won't be serialized, but will force reloading
44
+ }
45
if (_.isEqual(baseParams, lastReq.current)) return
46
lastReq.current = baseParams
47
@@ -54,7 +60,7 @@ export default function useFetchList() {
60
state.list = sort([...state.list, ...chunk.map(precalculate)])
61
}
62
const timer = setInterval(flush, 1000)
57
- const src = apiEvents(API, baseParams, (type, data) => {
63
+ const src = apiEvents('file_list', baseParams, (type, data) => {
64
if (!isMounted()) return
65
switch (type) {
66
case 'error':
@@ -66,7 +72,6 @@ export default function useFetchList() {
72
flush()
73
state.stopSearch?.()
74
state.loading = false
69
- lastReq.current = undefined
75
return
76
case 'msg':
77
state.loginRequired = false