2018-06-11 19:03:43 -07:00
|
|
|
import { fromJS, Map } from 'immutable';
|
2018-07-17 19:13:52 -04:00
|
|
|
import { Cursor } from 'netlify-cms-lib-util';
|
2018-06-11 19:03:43 -07:00
|
|
|
import {
|
|
|
|
ENTRIES_SUCCESS,
|
|
|
|
} from 'Actions/entries';
|
|
|
|
|
|
|
|
// Since pagination can be used for a variety of views (collections
|
|
|
|
// and searches are the most common examples), we namespace cursors by
|
|
|
|
// their type before storing them in the state.
|
|
|
|
export const selectCollectionEntriesCursor = (state, collectionName) =>
|
|
|
|
new Cursor(state.getIn(["cursorsByType", "collectionEntries", collectionName]));
|
|
|
|
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default cursors;
|