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,6 +1,5 @@
import { OrderedMap, fromJS } from 'immutable';
import { CONFIG_SUCCESS } from '../actions/config';
import { ENTRIES_REQUEST, ENTRIES_SUCCESS } from '../actions/entries';
export function collections(state = null, action) {
switch (action.type) {
@ -11,10 +10,6 @@ export function collections(state = null, action) {
map.set(collection.name, fromJS(collection));
});
});
case ENTRIES_REQUEST:
return state && state.setIn([action.payload.collection, 'isFetching'], true);
case ENTRIES_SUCCESS:
return state && state.setIn([action.payload.collection, 'entries'], fromJS(action.payload.entries));
default:
return state;
}

40
src/reducers/entries.js Normal file
View File

@ -0,0 +1,40 @@
import { Map, List, fromJS } from 'immutable';
import {
ENTRY_REQUEST, ENTRY_SUCCESS, ENTRIES_REQUEST, ENTRIES_SUCCESS
} from '../actions/entries';
export function entries(state = Map({entities: Map(), pages: Map()}), action) {
switch (action.type) {
case ENTRY_REQUEST:
return state.setIn(['entities', `${action.payload.collection}.${action.payload.slug}`, 'isFetching'], true);
case ENTRY_SUCCESS:
return state.setIn(
['entities', `${action.payload.collection}.${action.payload.entry.slug}`],
fromJS(action.payload.entry)
);
case ENTRIES_REQUEST:
return state.setIn(['pages', action.payload.collection, 'isFetching'], true);
case ENTRIES_SUCCESS:
const { collection, entries, pages } = action.payload;
return state.withMutations((map) => {
entries.forEach((entry) => (
map.setIn(['entities', `${collection}.${entry.slug}`], fromJS(entry).set('isFetching', false))
));
map.setIn(['pages', collection], Map({
...pages,
ids: List(entries.map((entry) => entry.slug))
}));
});
default:
return state;
}
}
export function selectEntry(state, collection, slug) {
return state.entries.getIn(['entities', `${collection}.${slug}`]);
}
export function selectEntries(state, collection) {
const slugs = state.entries.getIn(['pages', collection, 'ids']);
return slugs && slugs.map((slug) => selectEntry(state, collection, slug));
}