Skip to content

Commit 6eade2e

Browse files
committed
fix: entries loading
1 parent 1d9ff86 commit 6eade2e

File tree

2 files changed

+24
-26
lines changed

2 files changed

+24
-26
lines changed

packages/decap-cms-core/src/actions/entries.ts

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -157,17 +157,18 @@ export function entriesLoaded(
157157
collection: Collection,
158158
entries: EntryValue[],
159159
pagination: number | null,
160-
cursor: Cursor,
160+
cursor?: Cursor | Record<string, unknown> | null,
161161
append = true,
162162
hasMore = false,
163163
) {
164+
const safeCursor = cursor ? Cursor.create(cursor) : Cursor.create({});
164165
return {
165166
type: ENTRIES_SUCCESS,
166167
payload: {
167168
collection: collection.get('name'),
168169
entries,
169170
page: pagination,
170-
cursor: Cursor.create(cursor),
171+
cursor: safeCursor,
171172
append,
172173
hasMore,
173174
},
@@ -875,22 +876,22 @@ export function loadEntries(collection: Collection, page = 0) {
875876
if (loadAllEntries) {
876877
if (cachedEntries) {
877878
// Serve cached full set immediately
878-
dispatch(
879-
entriesLoaded(
880-
collection,
881-
cachedEntries,
882-
0,
883-
addAppendActionsToCursor(Cursor.create({})),
884-
false,
885-
false,
886-
),
887-
);
888-
if (isI18nCollection && paginationEnabled) {
889-
dispatch({
890-
type: SORT_ENTRIES_SUCCESS,
891-
payload: { collection: collectionName, entries: cachedEntries },
892-
});
893-
}
879+
dispatch(
880+
entriesLoaded(
881+
collection,
882+
cachedEntries,
883+
0,
884+
addAppendActionsToCursor(Cursor.create({})),
885+
false,
886+
false,
887+
),
888+
);
889+
if (isI18nCollection && paginationEnabled) {
890+
dispatch({
891+
type: SORT_ENTRIES_SUCCESS,
892+
payload: { collection: collectionName, entries: cachedEntries },
893+
});
894+
}
894895
} else {
895896
// Progressive loading loop
896897
const initial = await provider.listEntries(collection, 0);

packages/decap-cms-core/src/reducers/entries.ts

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -251,14 +251,11 @@ function entries(
251251
);
252252

253253
const ids = List(loadedEntries.map(entry => entry.slug));
254-
map.setIn(
255-
['pages', collection],
256-
Map({
257-
page,
258-
ids: append ? map.getIn(['pages', collection, 'ids'], List()).concat(ids) : ids,
259-
isFetching: hasMore, // keep fetching flag true until last page
260-
}),
261-
);
254+
const pageMap = Map({
255+
page,
256+
ids: append ? map.getIn(['pages', collection, 'ids'], List()).concat(ids) : ids,
257+
});
258+
map.setIn(['pages', collection], hasMore ? pageMap.set('isFetching', true) : pageMap);
262259

263260
// Update pagination metadata from cursor if available
264261
if (payload.cursor && payload.cursor.meta && payload.cursor.meta.get('count')) {

0 commit comments

Comments
 (0)