Fix search show more bar
This commit is contained in:
parent
fdf3b93c36
commit
073304aa9e
3 changed files with 15 additions and 5 deletions
|
@ -43,7 +43,7 @@ export function submitSearch() {
|
||||||
params: {
|
params: {
|
||||||
q: value,
|
q: value,
|
||||||
resolve: signedIn,
|
resolve: signedIn,
|
||||||
limit: 5,
|
limit: 10,
|
||||||
},
|
},
|
||||||
}).then(response => {
|
}).then(response => {
|
||||||
if (response.data.accounts) {
|
if (response.data.accounts) {
|
||||||
|
|
|
@ -25,6 +25,7 @@ class SearchResults extends ImmutablePureComponent {
|
||||||
dismissSuggestion: PropTypes.func.isRequired,
|
dismissSuggestion: PropTypes.func.isRequired,
|
||||||
searchTerm: PropTypes.string,
|
searchTerm: PropTypes.string,
|
||||||
intl: PropTypes.object.isRequired,
|
intl: PropTypes.object.isRequired,
|
||||||
|
noMoreResults: ImmutablePropTypes.map,
|
||||||
};
|
};
|
||||||
|
|
||||||
componentDidMount () {
|
componentDidMount () {
|
||||||
|
@ -45,6 +46,8 @@ class SearchResults extends ImmutablePureComponent {
|
||||||
|
|
||||||
handleLoadMoreHashtags = () => this.props.expandSearch('hashtags');
|
handleLoadMoreHashtags = () => this.props.expandSearch('hashtags');
|
||||||
|
|
||||||
|
showMoreResults = (searchType) => this.props.noMoreResults ? !this.props.noMoreResults.get(searchType) : true;
|
||||||
|
|
||||||
render () {
|
render () {
|
||||||
const { intl, results, suggestions, dismissSuggestion, searchTerm } = this.props;
|
const { intl, results, suggestions, dismissSuggestion, searchTerm } = this.props;
|
||||||
|
|
||||||
|
@ -82,7 +85,7 @@ class SearchResults extends ImmutablePureComponent {
|
||||||
|
|
||||||
{results.get('accounts').map(accountId => <AccountContainer key={accountId} id={accountId} />)}
|
{results.get('accounts').map(accountId => <AccountContainer key={accountId} id={accountId} />)}
|
||||||
|
|
||||||
{results.get('accounts').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreAccounts} />}
|
{this.showMoreResults('accounts') && <LoadMore visible onClick={this.handleLoadMoreAccounts} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
@ -95,7 +98,7 @@ class SearchResults extends ImmutablePureComponent {
|
||||||
|
|
||||||
{results.get('statuses').map(statusId => <StatusContainer key={statusId} id={statusId} />)}
|
{results.get('statuses').map(statusId => <StatusContainer key={statusId} id={statusId} />)}
|
||||||
|
|
||||||
{results.get('statuses').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreStatuses} />}
|
{this.showMoreResults('statuses') && <LoadMore visible onClick={this.handleLoadMoreStatuses} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
} else if(results.get('statuses') && results.get('statuses').size === 0 && !searchEnabled && !(searchTerm.startsWith('@') || searchTerm.startsWith('#') || searchTerm.includes(' '))) {
|
} else if(results.get('statuses') && results.get('statuses').size === 0 && !searchEnabled && !(searchTerm.startsWith('@') || searchTerm.startsWith('#') || searchTerm.includes(' '))) {
|
||||||
|
@ -118,7 +121,7 @@ class SearchResults extends ImmutablePureComponent {
|
||||||
|
|
||||||
{results.get('hashtags').map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
|
{results.get('hashtags').map(hashtag => <Hashtag key={hashtag.get('name')} hashtag={hashtag} />)}
|
||||||
|
|
||||||
{results.get('hashtags').size >= 5 && <LoadMore visible onClick={this.handleLoadMoreHashtags} />}
|
{this.showMoreResults('hashtags') && <LoadMore visible onClick={this.handleLoadMoreHashtags} />}
|
||||||
</div>
|
</div>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
|
@ -19,6 +19,7 @@ const initialState = ImmutableMap({
|
||||||
submitted: false,
|
submitted: false,
|
||||||
hidden: false,
|
hidden: false,
|
||||||
results: ImmutableMap(),
|
results: ImmutableMap(),
|
||||||
|
noMoreResults: ImmutableMap(),
|
||||||
isLoading: false,
|
isLoading: false,
|
||||||
searchTerm: '',
|
searchTerm: '',
|
||||||
});
|
});
|
||||||
|
@ -31,6 +32,7 @@ export default function search(state = initialState, action) {
|
||||||
return state.withMutations(map => {
|
return state.withMutations(map => {
|
||||||
map.set('value', '');
|
map.set('value', '');
|
||||||
map.set('results', ImmutableMap());
|
map.set('results', ImmutableMap());
|
||||||
|
map.set('noMoreResults', ImmutableMap());
|
||||||
map.set('submitted', false);
|
map.set('submitted', false);
|
||||||
map.set('hidden', false);
|
map.set('hidden', false);
|
||||||
});
|
});
|
||||||
|
@ -54,13 +56,18 @@ export default function search(state = initialState, action) {
|
||||||
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
statuses: ImmutableList(action.results.statuses.map(item => item.id)),
|
||||||
hashtags: fromJS(action.results.hashtags),
|
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('searchTerm', action.searchTerm);
|
||||||
map.set('isLoading', false);
|
map.set('isLoading', false);
|
||||||
});
|
});
|
||||||
case SEARCH_EXPAND_SUCCESS:
|
case SEARCH_EXPAND_SUCCESS:
|
||||||
const results = action.searchType === 'hashtags' ? fromJS(action.results.hashtags) : action.results[action.searchType].map(item => item.id);
|
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)).updateIn(['noMoreResults', action.searchType], results.size <= 0);
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue