{"size": 580, "ext": "js", "max_stars_repo_path": "src/reducers/index.js", "max_stars_repo_name": "rotyflo/quotes", "max_stars_repo_stars_event_min_datetime": null, "max_stars_repo_stars_event_max_datetime": null, "max_issues_repo_path": "src/reducers/index.js", "max_issues_repo_name": "rotyflo/quotes", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "src/reducers/index.js", "max_forks_repo_name": "rotyflo/quotes", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": null, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 26.3636363636, "max_line_length": 68, "alphanum_fraction": 0.7068965517}
const WRITE_QUOTES_TO_STATE = 'WRITE_QUOTES_TO_STATE';
const SET_RANDOM_INDEX = 'SET_RANDOM_INDEX';

const defaultState = {
	quotes: [{text: 'loading...', author: ''}],
	index: 0
}

export default function quoteReducer(state = defaultState, action) {
	switch (action.type) {
		case WRITE_QUOTES_TO_STATE:
			return Object.assign({}, state, {quotes: action.quotes});

		case SET_RANDOM_INDEX:
			let maxIndex = state.quotes.length;
			let randIndex = Math.round(Math.random() * maxIndex);
			return Object.assign({}, state, {index: randIndex});
		
		default:
			return state;
	}
};