Skip to content
This repository has been archived by the owner on Apr 5, 2024. It is now read-only.

Commit

Permalink
Remove scrolling to search results on search button click
Browse files Browse the repository at this point in the history
  • Loading branch information
Petri Mahanen authored and vharvala committed Jan 18, 2019
1 parent 9f76a18 commit e5429af
Show file tree
Hide file tree
Showing 3 changed files with 13 additions and 32 deletions.
37 changes: 12 additions & 25 deletions app/pages/search/SearchPage.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import isEqual from 'lodash/isEqual';
import React, { Component, PropTypes } from 'react';
import { findDOMNode } from 'react-dom';
import { connect } from 'react-redux';
import { bindActionCreators } from 'redux';

Expand All @@ -11,7 +10,6 @@ import { fetchUnits } from 'actions/unitActions';
import PageWrapper from 'pages/PageWrapper';
import { injectT } from 'i18n';
import ResourceMap from 'shared/resource-map';
import { scrollTo } from 'utils/domUtils';
import SearchControls from './controls';
import searchPageSelector from './searchPageSelector';
import SearchResults from './results/SearchResults';
Expand All @@ -20,7 +18,6 @@ import MapToggle from './results/MapToggle';
class UnconnectedSearchPage extends Component {
constructor(props) {
super(props);
this.scrollToSearchResults = this.scrollToSearchResults.bind(this);
this.searchResources = this.searchResources.bind(this);
}

Expand Down Expand Up @@ -64,10 +61,6 @@ class UnconnectedSearchPage extends Component {
this.searchResources(nextFilters);
}

scrollToSearchResults() {
scrollTo(findDOMNode(this.refs.searchResults));
}

searchResources(filters, position = this.props.position || {}) {
this.props.actions.searchResources({ ...filters, ...position });
}
Expand All @@ -87,29 +80,21 @@ class UnconnectedSearchPage extends Component {
} = this.props;
return (
<div className="app-SearchPage">
<SearchControls
location={location}
params={params}
scrollToSearchResults={this.scrollToSearchResults}
/>
{!isFetchingSearchResults &&
<MapToggle
mapVisible={showMap}
onClick={actions.toggleMap}
resultCount={resultCount}
/>
}
{showMap &&
<SearchControls location={location} params={params} />
{!isFetchingSearchResults && (
<MapToggle mapVisible={showMap} onClick={actions.toggleMap} resultCount={resultCount} />
)}
{showMap && (
<ResourceMap
location={location}
resourceIds={searchResultIds}
selectedUnitId={selectedUnitId}
showMap={showMap}
/>
}
)}
<PageWrapper className="app-SearchPage__wrapper" title={t('SearchPage.title')} transparent>
<div className="app-SearchPage__content">
{(searchDone || isFetchingSearchResults) &&
{(searchDone || isFetchingSearchResults) && (
<SearchResults
isFetching={isFetchingSearchResults}
location={location}
Expand All @@ -119,9 +104,8 @@ class UnconnectedSearchPage extends Component {
selectedUnitId={selectedUnitId}
showMap={showMap}
/>
}
)}
</div>

</PageWrapper>
</div>
);
Expand Down Expand Up @@ -160,4 +144,7 @@ function mapDispatchToProps(dispatch) {
}

export { UnconnectedSearchPage };
export default connect(searchPageSelector, mapDispatchToProps)(UnconnectedSearchPage);
export default connect(
searchPageSelector,
mapDispatchToProps
)(UnconnectedSearchPage);
1 change: 0 additions & 1 deletion app/pages/search/SearchPage.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ describe('pages/search/SearchPage', () => {
expect(searchControls.length).to.equal(1);
expect(searchControls.prop('location')).to.deep.equal(defaultProps.location);
expect(searchControls.prop('params')).to.deep.equal(defaultProps.params);
expect(searchControls.prop('scrollToSearchResults')).to.be.a('function');
});

it('renders PageWrapper with correct props', () => {
Expand Down
7 changes: 1 addition & 6 deletions app/pages/search/controls/SearchControlsContainer.js
Original file line number Diff line number Diff line change
Expand Up @@ -101,14 +101,10 @@ class UnconnectedSearchControlsContainer extends Component {
}
};

handleSearch = (newFilters = {}, options = {}) => {
const { scrollToSearchResults } = this.props;
handleSearch = (newFilters = {}) => {
const page = 1;
const filters = { ...this.props.filters, ...newFilters, page };
browserHistory.push(`/search?${queryString.stringify(filters)}`);
if (!options.preventScrolling) {
scrollToSearchResults();
}
};

handleReset = () => {
Expand Down Expand Up @@ -256,7 +252,6 @@ UnconnectedSearchControlsContainer.propTypes = {
isFetchingUnits: PropTypes.bool.isRequired,
position: PropTypes.object,
purposeOptions: PropTypes.array.isRequired,
scrollToSearchResults: PropTypes.func.isRequired,
t: PropTypes.func.isRequired,
unitOptions: PropTypes.array.isRequired,
urlSearchFilters: PropTypes.object.isRequired,
Expand Down

0 comments on commit e5429af

Please sign in to comment.