Test repo can now be used to list entries
This commit is contained in:
@ -32,7 +32,7 @@ export function loadConfig(config) {
|
||||
return (dispatch, getState) => {
|
||||
dispatch(configLoading());
|
||||
|
||||
fetch('config.yml').then((response) => {
|
||||
fetch('/config.yml').then((response) => {
|
||||
if (response.status !== 200) {
|
||||
throw `Failed to load config.yml (${response.status})`;
|
||||
}
|
||||
|
49
src/actions/entries.js
Normal file
49
src/actions/entries.js
Normal file
@ -0,0 +1,49 @@
|
||||
import { currentBackend } from '../backends/backend';
|
||||
|
||||
export const ENTRIES_REQUEST = 'ENTRIES_REQUEST';
|
||||
export const ENTRIES_SUCCESS = 'ENTRIES_SUCCESS';
|
||||
export const ENTRIES_FAILURE = 'ENTRIES_FAILURE';
|
||||
|
||||
export function entriesLoaded(collection, entries) {
|
||||
return {
|
||||
type: ENTRIES_SUCCESS,
|
||||
payload: {
|
||||
collection: collection.get('name'),
|
||||
entries: entries
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
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')}
|
||||
};
|
||||
}
|
||||
|
||||
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)
|
||||
.then((entries) => dispatch(entriesLoaded(collection, entries)))
|
||||
.catch((err) => {
|
||||
console.error(err);
|
||||
return dispatch(entriesFailed(collection, err));
|
||||
});
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user