From de4e62df400d8f0826db344327b439f283141856 Mon Sep 17 00:00:00 2001 From: mbarto Date: Fri, 17 Feb 2017 16:45:52 +0100 Subject: [PATCH] Fixed 3D viewer example to work with search epic (#1488) --- web/client/actions/__tests__/search-test.js | 4 ++-- web/client/actions/search.js | 20 ++++---------------- web/client/epics/__tests__/search-test.js | 4 ++-- web/client/examples/3dviewer/stores/store.js | 9 ++++++++- web/client/plugins/Search.jsx | 6 +++--- 5 files changed, 19 insertions(+), 24 deletions(-) diff --git a/web/client/actions/__tests__/search-test.js b/web/client/actions/__tests__/search-test.js index db26c23d76..c77ab7d02c 100644 --- a/web/client/actions/__tests__/search-test.js +++ b/web/client/actions/__tests__/search-test.js @@ -15,13 +15,13 @@ var { searchResultLoaded, searchTextLoading, searchResultError, - searchTextStarted + textSearch } = require('../search'); describe('Test correctness of the search actions', () => { it('text search started', () => { - const action = searchTextStarted(true); + const action = textSearch(true); expect(action.type).toBe(TEXT_SEARCH_STARTED); }); it('text search loading', () => { diff --git a/web/client/actions/search.js b/web/client/actions/search.js index 1fa70ab87b..582b811aca 100644 --- a/web/client/actions/search.js +++ b/web/client/actions/search.js @@ -6,7 +6,6 @@ * LICENSE file in the root directory of this source tree. */ -var GeoCodingApi = require('../api/Nominatim'); const TEXT_SEARCH_STARTED = 'TEXT_SEARCH_STARTED'; const TEXT_SEARCH_RESULTS_LOADED = 'TEXT_SEARCH_RESULTS_LOADED'; const TEXT_SEARCH_PERFORMED = 'TEXT_SEARCH_PERFORMED'; @@ -32,12 +31,6 @@ function searchTextChanged(text) { }; } -function searchTextStarted(searchText) { - return { - type: TEXT_SEARCH_STARTED, - searchText - }; -} function searchTextLoading(loading) { return { type: TEXT_SEARCH_LOADING, @@ -71,14 +64,10 @@ function addMarker(itemPosition) { }; } -function textSearch(text) { - return (dispatch) => { - dispatch(searchTextStarted(text)); - GeoCodingApi.geocode(text).then((response) => { - dispatch(searchResultLoaded(response)); - }).catch((e) => { - dispatch(searchResultLoaded(e)); - }); +function textSearch(searchText) { + return { + type: TEXT_SEARCH_STARTED, + searchText }; } @@ -93,7 +82,6 @@ module.exports = { TEXT_SEARCH_RESET, TEXT_SEARCH_ADD_MARKER, TEXT_SEARCH_TEXT_CHANGE, - searchTextStarted, searchTextLoading, searchResultError, searchResultLoaded, diff --git a/web/client/epics/__tests__/search-test.js b/web/client/epics/__tests__/search-test.js index 24a0008d1a..3656eb2222 100644 --- a/web/client/epics/__tests__/search-test.js +++ b/web/client/epics/__tests__/search-test.js @@ -11,7 +11,7 @@ var expect = require('expect'); const configureMockStore = require('redux-mock-store').default; const { createEpicMiddleware } = require('redux-observable'); -const { searchTextStarted, TEXT_SEARCH_RESULTS_LOADED, TEXT_SEARCH_LOADING } = require('../../actions/search'); +const { textSearch, TEXT_SEARCH_RESULTS_LOADED, TEXT_SEARCH_LOADING } = require('../../actions/search'); const {searchEpic} = require('../search'); const epicMiddleware = createEpicMiddleware(searchEpic); const mockStore = configureMockStore([epicMiddleware]); @@ -29,7 +29,7 @@ describe('searchEpic', () => { it('produces the search epic', (done) => { let action = { - ...searchTextStarted("TEST"), + ...textSearch("TEST"), services: [{ type: 'wfs', options: { diff --git a/web/client/examples/3dviewer/stores/store.js b/web/client/examples/3dviewer/stores/store.js index 97cf9e6bf4..baa258deaa 100644 --- a/web/client/examples/3dviewer/stores/store.js +++ b/web/client/examples/3dviewer/stores/store.js @@ -8,6 +8,13 @@ var controls = require('../reducers/controls'); var mousePosition = require('../../../reducers/mousePosition'); var searchResults = require('../../../reducers/search'); +const {createEpicMiddleware, combineEpics } = require('redux-observable'); + +const {searchEpic} = require('../../../epics/search'); + +const rootEpic = combineEpics(searchEpic); +const epicMiddleware = createEpicMiddleware(rootEpic); + // reducers const reducers = combineReducers({ mapConfig, @@ -19,7 +26,7 @@ const reducers = combineReducers({ }); // compose middleware(s) to createStore -let finalCreateStore = applyMiddleware(thunkMiddleware)(createStore); +let finalCreateStore = applyMiddleware(thunkMiddleware, epicMiddleware)(createStore); // export the store with the given reducers (and middleware applied) module.exports = finalCreateStore(reducers, {}); diff --git a/web/client/plugins/Search.jsx b/web/client/plugins/Search.jsx index 8731a03b22..956cfcdb21 100644 --- a/web/client/plugins/Search.jsx +++ b/web/client/plugins/Search.jsx @@ -15,7 +15,7 @@ const assign = require('object-assign'); const HelpWrapper = require('./help/HelpWrapper'); const Message = require('./locale/Message'); -const {resultsPurge, resetSearch, addMarker, searchTextChanged, searchTextStarted} = require("../actions/search"); +const {resultsPurge, resetSearch, addMarker, searchTextChanged, textSearch} = require("../actions/search"); const {changeMapView} = require('../actions/map'); const searchSelector = createSelector([ @@ -27,8 +27,8 @@ const searchSelector = createSelector([ })); const SearchBar = connect(searchSelector, { - // ONLY FOR SAMPLE - The final one will get from state and simply call searchTextStarted - onSearch: searchTextStarted, + // ONLY FOR SAMPLE - The final one will get from state and simply call textSearch + onSearch: textSearch, onPurgeResults: resultsPurge, onSearchReset: resetSearch, onSearchTextChange: searchTextChanged