Skip to content

Commit 5336e4a

Browse files
committed
Don't show previous search results without a query
1 parent 7261d68 commit 5336e4a

File tree

2 files changed

+13
-4
lines changed

2 files changed

+13
-4
lines changed

src/search/containers/CurrentSearchPage.js

+6-2
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,12 @@ import { search } from 'core/api';
55
import SearchPage from 'search/components/SearchPage';
66
import { searchStart, searchLoad, searchFail } from 'search/actions';
77

8-
export function mapStateToProps(state) {
9-
return state.search;
8+
export function mapStateToProps(state, ownProps) {
9+
const { location } = ownProps;
10+
if (location.query.q === state.search.query) {
11+
return state.search;
12+
}
13+
return {};
1014
}
1115

1216
function performSearch({ dispatch, page, query, api }) {

tests/client/search/containers/TestCurrentSearchPage.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,16 @@ describe('CurrentSearchPage.mapStateToProps()', () => {
1313
cd: { slug: 'cd', name: 'cd-block' } },
1414
search: { query: 'ad-block', loading: false, results: [{ slug: 'ab', name: 'ad-block' }] },
1515
};
16-
const props = mapStateToProps(state);
1716

18-
it('passes the search state', () => {
17+
it('passes the search state if the URL and state query matches', () => {
18+
const props = mapStateToProps(state, { location: { query: { q: 'ad-block' } } });
1919
assert.strictEqual(props, state.search);
2020
});
21+
22+
it('does not pass search state if the URL and state query do not match', () => {
23+
const props = mapStateToProps(state, { location: { query: { q: 'more-ads' } } });
24+
assert.deepEqual(props, {});
25+
});
2126
});
2227

2328
describe('CurrentSearchPage.isLoaded()', () => {

0 commit comments

Comments
 (0)