diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index dcd0205fb..02313d009 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -10,12 +10,12 @@ export const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST'; export const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS'; export const SEARCH_FETCH_FAIL = 'SEARCH_FETCH_FAIL'; +export const SEARCH_FILTER_SET = 'SEARCH_FILTER_SET'; + export const SEARCH_EXPAND_REQUEST = 'SEARCH_EXPAND_REQUEST'; export const SEARCH_EXPAND_SUCCESS = 'SEARCH_EXPAND_SUCCESS'; export const SEARCH_EXPAND_FAIL = 'SEARCH_EXPAND_FAIL'; -export const SEARCH_FILTER_SET = 'SEARCH_FILTER_SET'; - export function changeSearch(value) { return { type: SEARCH_CHANGE, @@ -82,6 +82,14 @@ export function fetchSearchFail(error) { }; } +export const setFilter = filterType => dispatch => { + dispatch({ + type: SEARCH_FILTER_SET, + path: ['search', 'filter'], + value: filterType, + }); +}; + export const expandSearch = type => (dispatch, getState) => { const value = getState().getIn(['search', 'value']); const offset = getState().getIn(['search', 'results', type]).size; diff --git a/app/soapbox/features/compose/components/search_results.js b/app/soapbox/features/compose/components/search_results.js index be7ec9a9d..fd427e682 100644 --- a/app/soapbox/features/compose/components/search_results.js +++ b/app/soapbox/features/compose/components/search_results.js @@ -16,21 +16,15 @@ export default class SearchResults extends ImmutablePureComponent { results: ImmutablePropTypes.map.isRequired, submitted: PropTypes.bool, expandSearch: PropTypes.func.isRequired, - }; - - state = { - selectedFilter: 'accounts', + selectedFilter: PropTypes.string.isRequired, }; handleLoadMore = () => this.props.expandSearch(this.state.selectedFilter); - handleSelectFilter = newActiveFilter => { - this.setState({ selectedFilter: newActiveFilter }); - }; + handleSelectFilter = newActiveFilter => this.props.selectFilter(newActiveFilter); render() { - const { results, submitted } = this.props; - const { selectedFilter } = this.state; + const { results, submitted, selectedFilter } = this.props; if (submitted && results.isEmpty()) { return ( diff --git a/app/soapbox/features/compose/containers/search_results_container.js b/app/soapbox/features/compose/containers/search_results_container.js index 734612dce..f48d70150 100644 --- a/app/soapbox/features/compose/containers/search_results_container.js +++ b/app/soapbox/features/compose/containers/search_results_container.js @@ -1,13 +1,14 @@ import { connect } from 'react-redux'; import SearchResults from '../components/search_results'; import { fetchSuggestions, dismissSuggestion } from '../../../actions/suggestions'; -import { expandSearch } from '../../../actions/search'; +import { expandSearch, setFilter } from '../../../actions/search'; const mapStateToProps = state => { return { results: state.getIn(['search', 'results']), suggestions: state.getIn(['suggestions', 'items']), submitted: state.getIn(['search', 'submitted']), + selectedFilter: state.getIn(['search', 'filter']), }; }; @@ -15,6 +16,7 @@ const mapDispatchToProps = dispatch => ({ fetchSuggestions: () => dispatch(fetchSuggestions()), expandSearch: type => dispatch(expandSearch(type)), dismissSuggestion: account => dispatch(dismissSuggestion(account.get('id'))), + selectFilter: newActiveFilter => dispatch(setFilter(newActiveFilter)), }); export default connect(mapStateToProps, mapDispatchToProps)(SearchResults); diff --git a/app/soapbox/locales/pl.json b/app/soapbox/locales/pl.json index 712330361..6080d54af 100644 --- a/app/soapbox/locales/pl.json +++ b/app/soapbox/locales/pl.json @@ -188,6 +188,7 @@ "column.public": "Globalna oś czasu", "column.remote": "Sfederowana oś czasu", "column.scheduled_statuses": "Zaplanowane wpisy", + "column.search": "Szukaj", "column.security": "Bezpieczeństwo", "column.soapbox_config": "Konfiguracja Soapbox", "column_back_button.label": "Wróć", diff --git a/app/soapbox/reducers/__tests__/search-test.js b/app/soapbox/reducers/__tests__/search-test.js index fb74f1473..5151e5500 100644 --- a/app/soapbox/reducers/__tests__/search-test.js +++ b/app/soapbox/reducers/__tests__/search-test.js @@ -8,6 +8,7 @@ describe('search reducer', () => { submitted: false, hidden: false, results: ImmutableMap(), + filter: 'accounts', })); }); }); diff --git a/app/soapbox/reducers/search.js b/app/soapbox/reducers/search.js index ed2b66016..2bb65d0e9 100644 --- a/app/soapbox/reducers/search.js +++ b/app/soapbox/reducers/search.js @@ -4,6 +4,7 @@ import { SEARCH_FETCH_REQUEST, SEARCH_FETCH_SUCCESS, SEARCH_SHOW, + SEARCH_FILTER_SET, SEARCH_EXPAND_SUCCESS, } from '../actions/search'; import { @@ -18,6 +19,7 @@ const initialState = ImmutableMap({ submitted: false, hidden: false, results: ImmutableMap(), + filter: 'accounts', }); export default function search(state = initialState, action) { @@ -33,6 +35,7 @@ export default function search(state = initialState, action) { map.set('results', ImmutableMap()); map.set('submitted', false); map.set('hidden', false); + map.set('filter', 'accounts'); }); case SEARCH_SHOW: return state.set('hidden', false); @@ -53,7 +56,9 @@ export default function search(state = initialState, action) { accountsHasMore: action.results.accounts.length >= 20, statusesHasMore: action.results.statuses.length >= 20, hashtagsHasMore: action.results.hashtags.length >= 20, - })).set('submitted', true); + })).set('submitted', true).set('filter', 'accounts'); + case SEARCH_FILTER_SET: + return state.set('filter', action.value); case SEARCH_EXPAND_SUCCESS: return state.withMutations((state) => { state.setIn(['results', `${action.searchType}HasMore`], action.results[action.searchType].length >= 20);