diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index ee7bc1657..c974819fc 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -10,6 +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_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, @@ -76,8 +82,50 @@ export function fetchSearchFail(error) { }; }; -export function showSearch() { - return { - type: SEARCH_SHOW, - }; +export const expandSearch = type => (dispatch, getState) => { + const value = getState().getIn(['search', 'value']); + const offset = getState().getIn(['search', 'results', type]).size; + + dispatch(expandSearchRequest()); + + api(getState).get('/api/v2/search', { + params: { + q: value, + type, + offset, + }, + }).then(({ data }) => { + if (data.accounts) { + dispatch(importFetchedAccounts(data.accounts)); + } + + if (data.statuses) { + dispatch(importFetchedStatuses(data.statuses)); + } + + dispatch(expandSearchSuccess(data, value, type)); + dispatch(fetchRelationships(data.accounts.map(item => item.id))); + }).catch(error => { + dispatch(expandSearchFail(error)); + }); }; + +export const expandSearchRequest = () => ({ + type: SEARCH_EXPAND_REQUEST, +}); + +export const expandSearchSuccess = (results, searchTerm, searchType) => ({ + type: SEARCH_EXPAND_SUCCESS, + results, + searchTerm, + searchType, +}); + +export const expandSearchFail = error => ({ + type: SEARCH_EXPAND_FAIL, + error, +}); + +export const showSearch = () => ({ + type: SEARCH_SHOW, +}); diff --git a/app/soapbox/features/compose/components/search_results.js b/app/soapbox/features/compose/components/search_results.js index c7838f96a..5e8b31b8b 100644 --- a/app/soapbox/features/compose/components/search_results.js +++ b/app/soapbox/features/compose/components/search_results.js @@ -1,25 +1,36 @@ import React from 'react'; import PropTypes from 'prop-types'; import ImmutablePropTypes from 'react-immutable-proptypes'; -import { FormattedMessage, injectIntl } from 'react-intl'; import AccountContainer from '../../../containers/account_container'; import StatusContainer from '../../../containers/status_container'; import ImmutablePureComponent from 'react-immutable-pure-component'; import Hashtag from '../../../components/hashtag'; -import Icon from 'soapbox/components/icon'; import LoadingIndicator from 'soapbox/components/loading_indicator'; +import FilterBar from '../../search/components/filter_bar'; +import LoadMore from '../../../components/load_more'; +import classNames from 'classnames'; -export default @injectIntl -class SearchResults extends ImmutablePureComponent { +export default class SearchResults extends ImmutablePureComponent { static propTypes = { results: ImmutablePropTypes.map.isRequired, submitted: PropTypes.bool, - intl: PropTypes.object.isRequired, + expandSearch: PropTypes.func.isRequired, + }; + + state = { + selectedFilter: 'accounts', + }; + + handleLoadMore = () => this.props.expandSearch(this.state.selectedFilter); + + handleSelectFilter = newActiveFilter => { + this.setState({ selectedFilter: newActiveFilter }); }; render() { const { results, submitted } = this.props; + const { selectedFilter } = this.state; if (submitted && results.isEmpty()) { return ( @@ -29,53 +40,47 @@ class SearchResults extends ImmutablePureComponent { ); } - let accounts, statuses, hashtags; - let count = 0; + let searchResults; + let hasMore = false; - if (results.get('accounts') && results.get('accounts').size > 0) { - count += results.get('accounts').size; - accounts = ( -