fix: inconsistent state for file list if filtered and a reload happens (like after deleting)
Massimo Melina committed
Sep 25, 2023 at 11:23 UTC
db60226caf782ecc6b7114a3ce6e776024044b36
1 file changed
+7
-3
frontend/src/useFetchList.ts
+7
-3
@@ -53,8 +53,10 @@ export default function useFetchList() {
53
const buffer: DirList = []
54
const flush = () => {
55
const chunk = buffer.splice(0, Infinity)
56
- if (chunk.length)
56
+ if (chunk.length) {
57
state.list = sort([...state.list, ...chunk])
58
+ updateFilteredList()
59
+ }
60
}
61
const timer = setInterval(flush, 1000)
62
const src = apiEvents('get_file_list', params, (type, data) => {
@@ -149,9 +151,11 @@ const sortAgain = _.debounce(()=> state.list = sort(state.list), 100)
151
for (const k of [ 'sortBy', 'invertOrder', 'foldersFirst', 'sortNumerics'] as const)
152
subscribeKey(state, k, sortAgain)
153
152
-subscribeKey(state, 'patternFilter', v => {
154
+subscribeKey(state, 'patternFilter', updateFilteredList)
155
+function updateFilteredList() {
156
+ const v = state.patternFilter
157
if (!v)
158
return state.filteredList = undefined
159
const filter = new RegExp(_.escapeRegExp(v),'i')
160
state.filteredList = state.list.filter(x => filter.test(x.n))
157
-})
161
+}
\ No newline at end of file