2016-02-25 20:40:35 -08:00
|
|
|
import { currentBackend } from '../backends/backend';
|
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
export const ENTRY_REQUEST = 'ENTRY_REQUEST';
|
|
|
|
export const ENTRY_SUCCESS = 'ENTRY_SUCCESS';
|
|
|
|
export const ENTRY_FAILURE = 'ENTRY_FAILURE';
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
export const ENTRIES_REQUEST = 'ENTRIES_REQUEST';
|
|
|
|
export const ENTRIES_SUCCESS = 'ENTRIES_SUCCESS';
|
|
|
|
export const ENTRIES_FAILURE = 'ENTRIES_FAILURE';
|
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
export function entryLoading(collection, slug) {
|
|
|
|
return {
|
|
|
|
type: ENTRY_REQUEST,
|
|
|
|
payload: {
|
|
|
|
collection: collection.get('name'),
|
|
|
|
slug: slug
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function entryLoaded(collection, entry) {
|
|
|
|
return {
|
|
|
|
type: ENTRY_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
collection: collection.get('name'),
|
|
|
|
entry: entry
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function entriesLoaded(collection, entries, pagination) {
|
2016-02-25 20:40:35 -08:00
|
|
|
return {
|
|
|
|
type: ENTRIES_SUCCESS,
|
|
|
|
payload: {
|
|
|
|
collection: collection.get('name'),
|
2016-06-05 01:52:18 -07:00
|
|
|
entries: entries,
|
|
|
|
pages: pagination
|
2016-02-25 20:40:35 -08:00
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function entriesLoading(collection) {
|
|
|
|
return {
|
|
|
|
type: ENTRIES_REQUEST,
|
|
|
|
payload: {
|
|
|
|
collection: collection.get('name')
|
|
|
|
}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
export function entriesFailed(collection, error) {
|
|
|
|
return {
|
|
|
|
type: ENTRIES_FAILURE,
|
|
|
|
error: 'Failed to load entries',
|
|
|
|
payload: error.toString(),
|
|
|
|
meta: {collection: collection.get('name')}
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-06-05 01:52:18 -07:00
|
|
|
export function loadEntry(collection, slug) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
const state = getState();
|
|
|
|
const backend = currentBackend(state.config);
|
|
|
|
|
|
|
|
dispatch(entryLoading(collection, slug));
|
|
|
|
backend.entry(collection, slug)
|
|
|
|
.then((entry) => dispatch(entryLoaded(collection, entry)));
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
2016-02-25 20:40:35 -08:00
|
|
|
export function loadEntries(collection) {
|
|
|
|
return (dispatch, getState) => {
|
|
|
|
if (collection.get('isFetching')) { return; }
|
|
|
|
const state = getState();
|
|
|
|
const backend = currentBackend(state.config);
|
|
|
|
|
|
|
|
dispatch(entriesLoading(collection));
|
|
|
|
backend.entries(collection)
|
2016-06-05 01:52:18 -07:00
|
|
|
.then((response) => dispatch(entriesLoaded(collection, response.entries, response.pagination)))
|
2016-02-25 20:40:35 -08:00
|
|
|
};
|
|
|
|
}
|