From 073304aa9e1969fac7a9589072c7649f8cd1539c Mon Sep 17 00:00:00 2001 From: KMY Date: Wed, 5 Apr 2023 16:59:05 +0900 Subject: [PATCH] Fix search show more bar --- app/javascript/mastodon/actions/search.js | 2 +- .../features/compose/components/search_results.jsx | 9 ++++++--- app/javascript/mastodon/reducers/search.js | 9 ++++++++- 3 files changed, 15 insertions(+), 5 deletions(-) diff --git a/app/javascript/mastodon/actions/search.js b/app/javascript/mastodon/actions/search.js index 666c6c223b..0012808e5b 100644 --- a/app/javascript/mastodon/actions/search.js +++ b/app/javascript/mastodon/actions/search.js @@ -43,7 +43,7 @@ export function submitSearch() { params: { q: value, resolve: signedIn, - limit: 5, + limit: 10, }, }).then(response => { if (response.data.accounts) { diff --git a/app/javascript/mastodon/features/compose/components/search_results.jsx b/app/javascript/mastodon/features/compose/components/search_results.jsx index 44ab43638b..3882dec362 100644 --- a/app/javascript/mastodon/features/compose/components/search_results.jsx +++ b/app/javascript/mastodon/features/compose/components/search_results.jsx @@ -25,6 +25,7 @@ class SearchResults extends ImmutablePureComponent { dismissSuggestion: PropTypes.func.isRequired, searchTerm: PropTypes.string, intl: PropTypes.object.isRequired, + noMoreResults: ImmutablePropTypes.map, }; componentDidMount () { @@ -45,6 +46,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; @@ -82,7 +85,7 @@ class SearchResults extends ImmutablePureComponent { {results.get('accounts').map(accountId => )} - {results.get('accounts').size >= 5 && } + {this.showMoreResults('accounts') && } ); } @@ -95,7 +98,7 @@ class SearchResults extends ImmutablePureComponent { {results.get('statuses').map(statusId => )} - {results.get('statuses').size >= 5 && } + {this.showMoreResults('statuses') && } ); } 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 => )} - {results.get('hashtags').size >= 5 && } + {this.showMoreResults('hashtags') && } ); } diff --git a/app/javascript/mastodon/reducers/search.js b/app/javascript/mastodon/reducers/search.js index d3e71da9d9..56ca3070c5 100644 --- a/app/javascript/mastodon/reducers/search.js +++ b/app/javascript/mastodon/reducers/search.js @@ -19,6 +19,7 @@ const initialState = ImmutableMap({ submitted: false, hidden: false, results: ImmutableMap(), + noMoreResults: ImmutableMap(), isLoading: false, searchTerm: '', }); @@ -31,6 +32,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); }); @@ -54,13 +56,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)).updateIn(['noMoreResults', action.searchType], results.size <= 0); default: return state; }