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-11-08 17:33:09 +01:00
|
|
|
import {
|
|
|
|
ENTRIES_SUCCESS,
|
|
|
|
SORT_ENTRIES_SUCCESS,
|
|
|
|
FILTER_ENTRIES_SUCCESS,
|
|
|
|
GROUP_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.
|
2021-02-08 20:01:21 +02:00
|
|
|
export function selectCollectionEntriesCursor(state, collectionName) {
|
|
|
|
return new Cursor(state.getIn(['cursorsByType', 'collectionEntries', collectionName]));
|
|
|
|
}
|
2018-06-11 19:03:43 -07:00
|
|
|
|
2021-02-08 20:01:21 +02:00
|
|
|
function cursors(state = fromJS({ cursorsByType: { collectionEntries: {} } }), action) {
|
2018-06-11 19:03:43 -07:00
|
|
|
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-11-08 17:33:09 +01:00
|
|
|
case FILTER_ENTRIES_SUCCESS:
|
|
|
|
case GROUP_ENTRIES_SUCCESS:
|
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;
|
|
|
|
}
|
2021-02-08 20:01:21 +02:00
|
|
|
}
|
2018-06-11 19:03:43 -07:00
|
|
|
|
|
|
|
export default cursors;
|