diff options
| author | Jules Laplace <julescarbon@gmail.com> | 2019-02-13 13:58:11 +0100 |
|---|---|---|
| committer | Jules Laplace <julescarbon@gmail.com> | 2019-02-13 13:58:11 +0100 |
| commit | 392ea8d0ba2fdc713ae156517b0575e8219b9f1c (patch) | |
| tree | bb29c19f9f0a2d970c39c813130361405fccbe4e /scraper/client/search/search.reducer.js | |
| parent | dc7d9cbba842472efb33186e97ee55751e4d50ca (diff) | |
adding geocode client
Diffstat (limited to 'scraper/client/search/search.reducer.js')
| -rw-r--r-- | scraper/client/search/search.reducer.js | 84 |
1 files changed, 84 insertions, 0 deletions
diff --git a/scraper/client/search/search.reducer.js b/scraper/client/search/search.reducer.js new file mode 100644 index 00000000..b9de60bd --- /dev/null +++ b/scraper/client/search/search.reducer.js @@ -0,0 +1,84 @@ +import * as types from '../types' +import session from '../session' + +const initialState = () => ({ + query: { reset: true }, + browse: { reset: true }, + options: { + thumbnailSize: session('thumbnailSize') || 'th', + perPage: parseInt(session('perPage'), 10) || 50, + groupByHash: session('groupByHash'), + } +}) + +const loadingState = { + query: { + query: { loading: true }, + results: [] + }, + loading: { + loading: true + } +} + +export default function searchReducer(state = initialState(), action) { + // console.log(action.type, action) + switch (action.type) { + case types.search.loading: + if (action.tag === 'query' && action.offset) { + return { + ...state, + query: { + ...state.query, + loadingMore: true, + } + } + } + return { + ...state, + [action.tag]: loadingState[action.tag] || loadingState.loading, + } + + case types.search.loaded: + if (action.tag === 'query' && action.offset) { + return { + ...state, + query: { + query: action.data.query, + results: [ + ...state.query.results, + ...action.data.results, + ], + loadingMore: false, + } + } + } + return { + ...state, + [action.tag]: action.data, + } + + case types.search.error: + return { + ...state, + [action.tag]: { error: action.err }, + } + + case types.search.panic: + return { + ...initialState(), + } + + case types.search.update_options: + session.setAll(action.opt) + return { + ...state, + options: { + ...action.opt, + } + } + + default: + return state + } +} |
