Skip to content

Commit

Permalink
Fixed 3D viewer example to work with search epic (#1488)
Browse files Browse the repository at this point in the history
  • Loading branch information
mbarto authored Feb 17, 2017
1 parent 1ea6993 commit de4e62d
Show file tree
Hide file tree
Showing 5 changed files with 19 additions and 24 deletions.
4 changes: 2 additions & 2 deletions web/client/actions/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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', () => {
Expand Down
20 changes: 4 additions & 16 deletions web/client/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand All @@ -32,12 +31,6 @@ function searchTextChanged(text) {
};
}

function searchTextStarted(searchText) {
return {
type: TEXT_SEARCH_STARTED,
searchText
};
}
function searchTextLoading(loading) {
return {
type: TEXT_SEARCH_LOADING,
Expand Down Expand Up @@ -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
};
}

Expand All @@ -93,7 +82,6 @@ module.exports = {
TEXT_SEARCH_RESET,
TEXT_SEARCH_ADD_MARKER,
TEXT_SEARCH_TEXT_CHANGE,
searchTextStarted,
searchTextLoading,
searchResultError,
searchResultLoaded,
Expand Down
4 changes: 2 additions & 2 deletions web/client/epics/__tests__/search-test.js
Original file line number Diff line number Diff line change
Expand Up @@ -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]);
Expand All @@ -29,7 +29,7 @@ describe('searchEpic', () => {

it('produces the search epic', (done) => {
let action = {
...searchTextStarted("TEST"),
...textSearch("TEST"),
services: [{
type: 'wfs',
options: {
Expand Down
9 changes: 8 additions & 1 deletion web/client/examples/3dviewer/stores/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand All @@ -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, {});
6 changes: 3 additions & 3 deletions web/client/plugins/Search.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -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([
Expand All @@ -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
Expand Down

0 comments on commit de4e62d

Please sign in to comment.