Load, display and edit entries from test repo and github

This commit is contained in:
Mathias Biilmann Christensen
2016-06-05 01:52:18 -07:00
parent 7601d3f5a1
commit 32e54cdbdc
16 changed files with 433 additions and 46 deletions

View File

@ -1,15 +1,40 @@
import { currentBackend } from '../backends/backend';
export const ENTRY_REQUEST = 'ENTRY_REQUEST';
export const ENTRY_SUCCESS = 'ENTRY_SUCCESS';
export const ENTRY_FAILURE = 'ENTRY_FAILURE';
export const ENTRIES_REQUEST = 'ENTRIES_REQUEST';
export const ENTRIES_SUCCESS = 'ENTRIES_SUCCESS';
export const ENTRIES_FAILURE = 'ENTRIES_FAILURE';
export function entriesLoaded(collection, entries) {
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) {
return {
type: ENTRIES_SUCCESS,
payload: {
collection: collection.get('name'),
entries: entries
entries: entries,
pages: pagination
}
};
}
@ -32,6 +57,17 @@ export function entriesFailed(collection, error) {
};
}
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)));
};
}
export function loadEntries(collection) {
return (dispatch, getState) => {
if (collection.get('isFetching')) { return; }
@ -40,10 +76,6 @@ export function loadEntries(collection) {
dispatch(entriesLoading(collection));
backend.entries(collection)
.then((entries) => dispatch(entriesLoaded(collection, entries)))
.catch((err) => {
console.error(err);
return dispatch(entriesFailed(collection, err));
});
.then((response) => dispatch(entriesLoaded(collection, response.entries, response.pagination)))
};
}