2018-07-28 14:33:42 -06:00
|
|
|
import { fromJS } from 'immutable';
|
2018-07-17 19:13:52 -04:00
|
|
|
import { Cursor } from 'netlify-cms-lib-util';
|
2020-04-01 06:13:27 +03:00
|
|
|
import { ENTRIES_SUCCESS, SORT_ENTRIES_SUCCESS } from 'Actions/entries';
|
2018-06-11 19:03:43 -07:00
|
|
|
|
|
|
|
// 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) =>
|
2018-08-07 14:46:54 -06:00
|
|
|
new Cursor(state.getIn(['cursorsByType', 'collectionEntries', collectionName]));
|
2018-06-11 19:03:43 -07:00
|
|
|
|
|
|
|
const cursors = (state = fromJS({ cursorsByType: { collectionEntries: {} } }), action) => {
|
|
|
|
switch (action.type) {
|
|
|
|
case ENTRIES_SUCCESS: {
|
|
|
|
return state.setIn(
|
2018-08-07 14:46:54 -06:00
|
|
|
['cursorsByType', 'collectionEntries', action.payload.collection],
|
|
|
|
Cursor.create(action.payload.cursor).store,
|
2018-06-11 19:03:43 -07:00
|
|
|
);
|
|
|
|
}
|
2020-04-01 06:13:27 +03:00
|
|
|
case SORT_ENTRIES_SUCCESS: {
|
|
|
|
return state.deleteIn(['cursorsByType', 'collectionEntries', action.payload.collection]);
|
|
|
|
}
|
2018-06-11 19:03:43 -07:00
|
|
|
default:
|
|
|
|
return state;
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
export default cursors;
|