fix: (regression beta) search for a folder, click on result: we're in the folder but the search status is not reset, and no file is listed

Massimo Melina committed Jun 27, 2024 at 14:30 UTC a59002b3da5a11b7558b8381eedae5dbd43f87d1
1 file changed +10 -7
frontend/src/useFetchList.ts
+10 -7
@@ -27,7 +27,7 @@ export default function useFetchList() {
27 const uri = usePath() // this api can still work removing the initial slash, but then we'll have a mixed situation that will require plugins an extra effort
28 const search = snap.remoteSearch || undefined
29 const lastUri = useRef('')
30 - const lastReq = useRef<any>()
30 + const lastParams = useRef<any>()
31 const lastReloader = useRef(snap.listReloader)
32 const isMounted = useIsMounted()
33 const navigate = useNavigate()
@@ -48,8 +48,8 @@ export default function useFetchList() {
48 }
49
50 const params = { uri, search }
51 - if (snap.listReloader === lastReloader.current && _.isEqual(params, lastReq.current)) return
52 - lastReq.current = params
51 + if (snap.listReloader === lastReloader.current && _.isEqual(params, lastParams.current)) return
52 + lastParams.current = params
53 lastReloader.current = snap.listReloader
54
55 state.list = []
@@ -71,7 +71,7 @@ export default function useFetchList() {
71 case 'error':
72 state.stopSearch?.()
73 state.error = t`connection error`
74 - lastReq.current = null
74 + lastParams.current = null
75 return
76 case 'closed':
77 flush()
@@ -103,7 +103,7 @@ export default function useFetchList() {
103 void alertDialog(t('wrong_account', { u: snap.username }, "Account {u} has no access, try another"), 'warning')
104 })
105 state.loginRequired = error === HTTP_UNAUTHORIZED
106 - lastReq.current = null
106 + lastParams.current = null
107 continue
108 }
109 if (uri && !uri.endsWith('/')) // now we know it was a folder for sure
@@ -119,14 +119,17 @@ export default function useFetchList() {
119 return state.stopSearch?.()
120 }
121 })
122 - return state.stopSearch = () => {
122 + state.stopSearch = () => {
123 state.stopSearch = undefined
124 buffer.length = 0
125 - lastReq.current = lastUri.current = ''
125 state.loading = false
126 clearInterval(timer)
127 src.close()
128 }
129 + return () => {
130 + state.stopSearch?.()
131 + lastParams.current = null
132 + }
133 }, [uri, search, snap.username, snap.listReloader, loginRequired])
134 }
135