Merge branch 'kb_development' into kb_migration
This commit is contained in:
commit
86915f0cdb
9 changed files with 72 additions and 8 deletions
|
@ -46,7 +46,7 @@ export function submitSearch(type) {
|
|||
params: {
|
||||
q: value,
|
||||
resolve: signedIn,
|
||||
limit: 5,
|
||||
limit: 10,
|
||||
type,
|
||||
},
|
||||
}).then(response => {
|
||||
|
|
|
@ -24,6 +24,7 @@ class SearchResults extends ImmutablePureComponent {
|
|||
dismissSuggestion: PropTypes.func.isRequired,
|
||||
searchTerm: PropTypes.string,
|
||||
intl: PropTypes.object.isRequired,
|
||||
noMoreResults: ImmutablePropTypes.map,
|
||||
};
|
||||
|
||||
componentDidMount () {
|
||||
|
@ -44,6 +45,8 @@ class SearchResults extends ImmutablePureComponent {
|
|||
|
||||
handleLoadMoreHashtags = () => this.props.expandSearch('hashtags');
|
||||
|
||||
showMoreResults = (searchType) => this.props.noMoreResults ? !this.props.noMoreResults.get(searchType) : true;
|
||||
|
||||
render () {
|
||||
const { intl, results, suggestions, dismissSuggestion, searchTerm } = this.props;
|
||||
|
||||
|
@ -75,26 +78,28 @@ class SearchResults extends ImmutablePureComponent {
|
|||
|
||||
if (results.get('accounts') && results.get('accounts').size > 0) {
|
||||
count += results.get('accounts').size;
|
||||
const showMore = this.showMoreResults('accounts');
|
||||
accounts = (
|
||||
<div className='search-results__section'>
|
||||
<h5><Icon id='users' fixedWidth /><FormattedMessage id='search_results.accounts' defaultMessage='Profiles' /></h5>
|
||||
|
||||
{results.get('accounts').map(accountId => <AccountContainer key={accountId} id={accountId} />)}
|
||||
|
||||
{results.get('accounts').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreAccounts} />}
|
||||
{showMore && <LoadMore visible onClick={this.handleLoadMoreAccounts} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
if (results.get('statuses') && results.get('statuses').size > 0) {
|
||||
count += results.get('statuses').size;
|
||||
const showMore = this.showMoreResults('statuses');
|
||||
statuses = (
|
||||
<div className='search-results__section'>
|
||||
<h5><Icon id='quote-right' fixedWidth /><FormattedMessage id='search_results.statuses' defaultMessage='Posts' /></h5>
|
||||
|
||||
{results.get('statuses').map(statusId => <StatusContainer key={statusId} id={statusId} />)}
|
||||
|
||||
{results.get('statuses').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreStatuses} />}
|
||||
{showMore && <LoadMore visible onClick={this.handleLoadMoreStatuses} />}
|
||||
</div>
|
||||
);
|
||||
} else if(results.get('statuses') && results.get('statuses').size === 0 && !searchEnabled && !(searchTerm.startsWith('@') || searchTerm.startsWith('#') || searchTerm.includes(' '))) {
|
||||
|
@ -111,13 +116,14 @@ class SearchResults extends ImmutablePureComponent {
|
|||
|
||||
if (results.get('hashtags') && results.get('hashtags').size > 0) {
|
||||
count += results.get('hashtags').size;
|
||||
const showMore = this.showMoreResults('hashtags');
|
||||
hashtags = (
|
||||
<div className='search-results__section'>
|
||||
<h5><Icon id='hashtag' fixedWidth /><FormattedMessage id='search_results.hashtags' defaultMessage='Hashtags' /></h5>
|
||||
|
||||
{results.get('hashtags').map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
|
||||
|
||||
{results.get('hashtags').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreHashtags} />}
|
||||
{showMore && <LoadMore visible onClick={this.handleLoadMoreHashtags} />}
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
|
|
@ -21,6 +21,7 @@ const initialState = ImmutableMap({
|
|||
submitted: false,
|
||||
hidden: false,
|
||||
results: ImmutableMap(),
|
||||
noMoreResults: ImmutableMap(),
|
||||
isLoading: false,
|
||||
searchTerm: '',
|
||||
recent: ImmutableOrderedSet(),
|
||||
|
@ -34,6 +35,7 @@ export default function search(state = initialState, action) {
|
|||
return state.withMutations(map => {
|
||||
map.set('value', '');
|
||||
map.set('results', ImmutableMap());
|
||||
map.set('noMoreResults', ImmutableMap());
|
||||
map.set('submitted', false);
|
||||
map.set('hidden', false);
|
||||
});
|
||||
|
@ -57,13 +59,18 @@ export default function search(state = initialState, action) {
|
|||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||
hashtags: fromJS(action.results.hashtags),
|
||||
}));
|
||||
map.set('noMoreResults', ImmutableMap({
|
||||
accounts: action.results.accounts.length <= 0,
|
||||
statuses: action.results.statuses.length <= 0,
|
||||
hashtags: false,
|
||||
}));
|
||||
|
||||
map.set('searchTerm', action.searchTerm);
|
||||
map.set('isLoading', false);
|
||||
});
|
||||
case SEARCH_EXPAND_SUCCESS:
|
||||
const results = action.searchType === 'hashtags' ? fromJS(action.results.hashtags) : action.results[action.searchType].map(item => item.id);
|
||||
return state.updateIn(['results', action.searchType], list => list.concat(results));
|
||||
return state.updateIn(['results', action.searchType], list => list.concat(results)).setIn(['noMoreResults', action.searchType], results.size <= 0);
|
||||
case SEARCH_RESULT_CLICK:
|
||||
return state.update('recent', set => set.add(fromJS(action.result)));
|
||||
case SEARCH_RESULT_FORGET:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue