Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
.then((response: { cursor: typeof Cursor }) => ({
...response,
// The only existing backend using the pagination system is the
// Algolia integration, which is also the only integration used
// to list entries. Thus, this checking for an integration can
// determine whether or not this is using the old integer-based
// pagination API. Other backends will simply store an empty
// cursor, which behaves identically to no cursor at all.
cursor: integration
? Cursor.create({
actions: ['next'],
meta: { usingOldPaginationAPI: true },
data: { nextPage: page + 1 },
})
: Cursor.create(response.cursor),
}))
.then((response: { cursor: typeof Cursor; pagination: number; entries: EntryValue[] }) =>
export function entriesLoaded(
collection: Collection,
entries: EntryValue[],
pagination: number | null,
cursor: typeof Cursor,
append = true,
) {
return {
type: ENTRIES_SUCCESS,
payload: {
collection: collection.get('name'),
entries,
page: pagination,
cursor: Cursor.create(cursor),
append,
},
};
}
getCursor = () => {
const { page } = this.props;
return Cursor.create({
actions: isNaN(page) ? [] : ['append_next'],
});
};
hasMore = () => {
return Cursor.create(this.props.cursor).actions.has('append_next');
};
getEntriesAndCursor = jsonResponse => {
const {
size: count,
page: index,
pagelen: pageSize,
next,
previous: prev,
values: entries,
} = jsonResponse;
const pageCount = pageSize && count ? Math.ceil(count / pageSize) : undefined;
return {
entries,
cursor: Cursor.create({
actions: [...(next ? ['next'] : []), ...(prev ? ['prev'] : [])],
meta: { index, count, pageSize, pageCount },
data: { links: { next, prev } },
}),
};
};
const cursors = (state = fromJS({ cursorsByType: { collectionEntries: {} } }), action) => {
switch (action.type) {
case ENTRIES_SUCCESS: {
return state.setIn(
['cursorsByType', 'collectionEntries', action.payload.collection],
Cursor.create(action.payload.cursor).store,
);
}
default:
return state;
}
};
const addAppendActionsToCursor = (cursor: typeof Cursor) => {
return Cursor.create(cursor).updateStore('actions', (actions: Set) => {
return actions.union(
appendActions
.filter((v: Map) => actions.has(v.get('action') as string))
.keySeq(),
);
});
};
.then(async ({ entries, cursor: newCursor }) => ({
entries: this.processEntries(entries, collection),
cursor: Cursor.create(newCursor).wrapData({
cursorType: 'collectionEntries',
collection,
}),
}));
}