diff options
Diffstat (limited to 'src/redux')
| -rw-r--r-- | src/redux/github/actions.js | 17 | ||||
| -rw-r--r-- | src/redux/github/reducer.js | 10 | ||||
| -rw-r--r-- | src/redux/github/types.js | 1 | ||||
| -rw-r--r-- | src/redux/reducers.js | 2 |
4 files changed, 27 insertions, 3 deletions
diff --git a/src/redux/github/actions.js b/src/redux/github/actions.js index 2db93ce..7f843c4 100644 --- a/src/redux/github/actions.js +++ b/src/redux/github/actions.js @@ -3,7 +3,8 @@ import axios from 'axios'; import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, - PROCESS_FETCH_TRENDING + PROCESS_FETCH_TRENDING, + UPDATE_FILTERS } from './types'; const API_URL = 'https://api.github.com/search/repositories'; @@ -31,3 +32,17 @@ export const fetchTrending = function (filters) { }); }; }; + +/** + * Updates the filters used in queries + * @param filters + * @return {Function} + */ +export const updateFilters = function (filters) { + return dispatch => { + dispatch({ + type: UPDATE_FILTERS, + payload: filters + }); + }; +}; diff --git a/src/redux/github/reducer.js b/src/redux/github/reducer.js index c752e36..66a11b5 100644 --- a/src/redux/github/reducer.js +++ b/src/redux/github/reducer.js @@ -1,8 +1,9 @@ -import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING } from './types'; +import { FETCH_TRENDING_FAILED, FETCH_TRENDING_SUCCESS, PROCESS_FETCH_TRENDING, UPDATE_FILTERS } from './types'; export const initialState = { processing: false, error: null, + filters: {}, data: [], }; @@ -24,9 +25,14 @@ export default function reducer(state = initialState, action) { case FETCH_TRENDING_FAILED: return { ...state, - process: false, + processing: false, error: action.payload }; + case UPDATE_FILTERS: + return { + ...state, + filters: action.payload + }; default: return state; } diff --git a/src/redux/github/types.js b/src/redux/github/types.js index a345496..c5be4bc 100644 --- a/src/redux/github/types.js +++ b/src/redux/github/types.js @@ -1,3 +1,4 @@ export const PROCESS_FETCH_TRENDING = 'PROCESS_FETCH_TRENDING'; export const FETCH_TRENDING_SUCCESS = 'FETCH_TRENDING_SUCCESS'; export const FETCH_TRENDING_FAILED = 'FETCH_TRENDING_FAILED'; +export const UPDATE_FILTERS = 'UPDATE_FILTERS'; diff --git a/src/redux/reducers.js b/src/redux/reducers.js index 7afbc67..912bfd5 100644 --- a/src/redux/reducers.js +++ b/src/redux/reducers.js @@ -1,7 +1,9 @@ import { combineReducers } from 'redux'; import preference from './preference/reducer'; +import github from './github/reducer'; export default combineReducers({ + github, preference, }); |
