@kaspernj/api-maker 1.0.324 → 1.0.325
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/package.json +1 -1
- package/src/use-collection.mjs +36 -26
package/package.json
CHANGED
package/src/use-collection.mjs
CHANGED
|
@@ -46,21 +46,23 @@ const useCollection = (
|
|
|
46
46
|
|
|
47
47
|
if (!queryName) queryName = digg(modelClass.modelClassData(), "collectionKey")
|
|
48
48
|
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
49
|
+
s.useStates({
|
|
50
|
+
models: undefined,
|
|
51
|
+
overallCount: undefined,
|
|
52
|
+
query: undefined,
|
|
53
|
+
queryName,
|
|
54
|
+
queryPerKey: `${queryName}_per`,
|
|
55
|
+
queryQName: `${queryName}_q`,
|
|
56
|
+
querySName: `${queryName}_s`,
|
|
57
|
+
queryPageName: `${queryName}_page`,
|
|
58
|
+
qParams: undefined,
|
|
59
|
+
result: undefined,
|
|
60
|
+
searchParams: undefined,
|
|
61
|
+
showNoRecordsAvailableContent: false,
|
|
62
|
+
showNoRecordsFoundContent: false
|
|
63
|
+
})
|
|
64
|
+
|
|
62
65
|
const queryParams = useQueryParams()
|
|
63
|
-
const modelIds = s.s.models?.map((model) => model.id())
|
|
64
66
|
|
|
65
67
|
let modelIdsCacheString
|
|
66
68
|
|
|
@@ -69,7 +71,7 @@ const useCollection = (
|
|
|
69
71
|
} else if (s.s.models.length === 0) {
|
|
70
72
|
modelIdsCacheString = "no-models"
|
|
71
73
|
} else {
|
|
72
|
-
modelIdsCacheString =
|
|
74
|
+
modelIdsCacheString = s.s.models.map((model) => model.cacheKey())?.join("---")
|
|
73
75
|
}
|
|
74
76
|
|
|
75
77
|
s.updateMeta({queryParams})
|
|
@@ -78,9 +80,11 @@ const useCollection = (
|
|
|
78
80
|
const baseQuery = s.p.collection || s.p.modelClass.all()
|
|
79
81
|
const overallCount = await baseQuery.count()
|
|
80
82
|
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
83
|
+
s.set({
|
|
84
|
+
overallCount,
|
|
85
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({overallCount}),
|
|
86
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({overallCount})
|
|
87
|
+
})
|
|
84
88
|
}, [])
|
|
85
89
|
|
|
86
90
|
const hasQParams = useCallback(() => {
|
|
@@ -107,8 +111,10 @@ const useCollection = (
|
|
|
107
111
|
}
|
|
108
112
|
}
|
|
109
113
|
|
|
110
|
-
|
|
111
|
-
|
|
114
|
+
s.set({
|
|
115
|
+
qParams: qParamsToSet,
|
|
116
|
+
searchParams
|
|
117
|
+
})
|
|
112
118
|
}, [])
|
|
113
119
|
|
|
114
120
|
const loadModels = useCallback(async () => {
|
|
@@ -160,16 +166,20 @@ const useCollection = (
|
|
|
160
166
|
})
|
|
161
167
|
}
|
|
162
168
|
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
169
|
+
s.set({
|
|
170
|
+
models: result.models(),
|
|
171
|
+
query,
|
|
172
|
+
result,
|
|
173
|
+
showNoRecordsAvailableContent: showNoRecordsAvailableContent({models}),
|
|
174
|
+
showNoRecordsFoundContent: showNoRecordsFoundContent({models})
|
|
175
|
+
})
|
|
168
176
|
}, [])
|
|
169
177
|
|
|
170
178
|
const loadModelsDebounce = useCallback(debounce(loadModels), [])
|
|
171
179
|
const onModelDestroyed = useCallback((args) => {
|
|
172
|
-
|
|
180
|
+
s.set({
|
|
181
|
+
models: s.s.models.filter((model) => model.id() != args.model.id())
|
|
182
|
+
})
|
|
173
183
|
}, [])
|
|
174
184
|
|
|
175
185
|
const onModelUpdated = useCallback((args) => {
|