@stoker-platform/web-app 0.5.125 → 0.5.126
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/package.json +1 -1
- package/src/Collection.tsx +4 -5
- package/src/providers/LoadingProvider.tsx +29 -19
package/CHANGELOG.md
CHANGED
package/package.json
CHANGED
package/src/Collection.tsx
CHANGED
|
@@ -710,15 +710,15 @@ function Collection({
|
|
|
710
710
|
const cacheLoading = useCallback(() => {
|
|
711
711
|
if (!cacheLoadingStarted.current) {
|
|
712
712
|
isCacheLoading.current = true
|
|
713
|
-
setIsRouteLoading("+", location.pathname)
|
|
713
|
+
setIsRouteLoading("+", location.pathname, true)
|
|
714
714
|
cacheLoadingStarted.current = true
|
|
715
715
|
}
|
|
716
|
-
}, [location
|
|
716
|
+
}, [location.pathname, setIsRouteLoading])
|
|
717
717
|
const cacheLoaded = useCallback(() => {
|
|
718
718
|
isCacheLoading.current = false
|
|
719
|
-
setIsRouteLoading("-", location.pathname)
|
|
719
|
+
setIsRouteLoading("-", location.pathname, true)
|
|
720
720
|
setCacheLoadingCompleted(true)
|
|
721
|
-
}, [location,
|
|
721
|
+
}, [location.pathname, setIsRouteLoading])
|
|
722
722
|
|
|
723
723
|
const hasRunSingleton = useRef(false)
|
|
724
724
|
|
|
@@ -727,7 +727,6 @@ function Collection({
|
|
|
727
727
|
const isPreloading = getLoadingState()[labels.collection]
|
|
728
728
|
if (!isPreloading || isPreloading === "Loading") {
|
|
729
729
|
cacheLoading()
|
|
730
|
-
cacheLoadingStarted.current = true
|
|
731
730
|
}
|
|
732
731
|
document.addEventListener(`stoker:loading:${labels.collection}`, cacheLoading)
|
|
733
732
|
// Prevent UI flicker
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { createContext, useContext,
|
|
1
|
+
import { createContext, useCallback, useContext, useRef, useState } from "react"
|
|
2
2
|
import debounce from "lodash/debounce.js"
|
|
3
3
|
import { serverReadOnly } from "@/utils/serverReadOnly"
|
|
4
4
|
import { useLocation } from "react-router"
|
|
@@ -91,25 +91,33 @@ export const RouteLoadingProvider: React.FC<RouteLoadingProviderProps> = ({ chil
|
|
|
91
91
|
const [isRouteLoading, setLoading] = useState<Set<string>>(new Set<string>())
|
|
92
92
|
const [isRouteLoadingImmediate, setLoadingImmediate] = useState<Set<string>>(new Set<string>())
|
|
93
93
|
|
|
94
|
-
const
|
|
95
|
-
const debouncedSet = debounce((operation: "+" | "-", route: string) => {
|
|
96
|
-
if (operation === "+") {
|
|
97
|
-
setLoading((prev) => {
|
|
98
|
-
const newSet = new Set(prev)
|
|
99
|
-
newSet.add(route)
|
|
100
|
-
return newSet
|
|
101
|
-
})
|
|
102
|
-
} else {
|
|
103
|
-
setLoading((prev) => {
|
|
104
|
-
const newSet = new Set(prev)
|
|
105
|
-
newSet.delete(route)
|
|
106
|
-
return newSet
|
|
107
|
-
})
|
|
108
|
-
}
|
|
109
|
-
}, 500)
|
|
94
|
+
const debouncedByRouteRef = useRef(new Map<string, ReturnType<typeof debounce>>())
|
|
110
95
|
|
|
111
|
-
|
|
112
|
-
|
|
96
|
+
const setIsRouteLoadingDebounced = useCallback((operation: "+" | "-", route: string) => {
|
|
97
|
+
let debounced = debouncedByRouteRef.current.get(route)
|
|
98
|
+
if (!debounced) {
|
|
99
|
+
debounced = debounce((op: "+" | "-") => {
|
|
100
|
+
if (op === "+") {
|
|
101
|
+
setLoading((prev) => {
|
|
102
|
+
const newSet = new Set(prev)
|
|
103
|
+
newSet.add(route)
|
|
104
|
+
return newSet
|
|
105
|
+
})
|
|
106
|
+
} else {
|
|
107
|
+
setLoading((prev) => {
|
|
108
|
+
const newSet = new Set(prev)
|
|
109
|
+
newSet.delete(route)
|
|
110
|
+
return newSet
|
|
111
|
+
})
|
|
112
|
+
}
|
|
113
|
+
}, 500)
|
|
114
|
+
debouncedByRouteRef.current.set(route, debounced)
|
|
115
|
+
}
|
|
116
|
+
debounced(operation)
|
|
117
|
+
if (operation === "-") {
|
|
118
|
+
debounced.flush()
|
|
119
|
+
debounced.cancel()
|
|
120
|
+
debouncedByRouteRef.current.delete(route)
|
|
113
121
|
}
|
|
114
122
|
}, [])
|
|
115
123
|
|
|
@@ -153,6 +161,8 @@ export const RouteLoadingProvider: React.FC<RouteLoadingProviderProps> = ({ chil
|
|
|
153
161
|
// eslint-disable-next-line security/detect-object-injection
|
|
154
162
|
const collection = schema.collections[collectionName]
|
|
155
163
|
if ((collection && serverReadOnly(collection)) || immediate) {
|
|
164
|
+
debouncedByRouteRef.current.get(route)?.cancel()
|
|
165
|
+
debouncedByRouteRef.current.delete(route)
|
|
156
166
|
setIsRouteLoadingImmediate(operation, route)
|
|
157
167
|
} else {
|
|
158
168
|
setIsRouteLoadingDebounced(operation, route)
|