From 403d6ae48c3ab70ede0b26867992760258d6b155 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 7 Aug 2021 20:42:39 +0200 Subject: [PATCH 1/2] Search results improvements MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/actions/search.js | 5 +- .../compose/components/search_results.js | 54 ++++++++++++++----- .../containers/search_results_container.js | 1 + app/soapbox/reducers/__tests__/search-test.js | 1 + app/soapbox/reducers/search.js | 2 + 5 files changed, 47 insertions(+), 16 deletions(-) diff --git a/app/soapbox/actions/search.js b/app/soapbox/actions/search.js index c974819fc..d9585ea4e 100644 --- a/app/soapbox/actions/search.js +++ b/app/soapbox/actions/search.js @@ -37,7 +37,7 @@ export function submitSearch() { return; } - dispatch(fetchSearchRequest()); + dispatch(fetchSearchRequest(value)); api(getState).get('/api/v2/search', { params: { @@ -62,9 +62,10 @@ export function submitSearch() { }; }; -export function fetchSearchRequest() { +export function fetchSearchRequest(value) { return { type: SEARCH_FETCH_REQUEST, + value, }; }; diff --git a/app/soapbox/features/compose/components/search_results.js b/app/soapbox/features/compose/components/search_results.js index 5e8b31b8b..3fb46bb65 100644 --- a/app/soapbox/features/compose/components/search_results.js +++ b/app/soapbox/features/compose/components/search_results.js @@ -1,5 +1,6 @@ import React from 'react'; import PropTypes from 'prop-types'; +import { FormattedMessage } from 'react-intl'; import ImmutablePropTypes from 'react-immutable-proptypes'; import AccountContainer from '../../../containers/account_container'; import StatusContainer from '../../../containers/status_container'; @@ -13,6 +14,7 @@ import classNames from 'classnames'; export default class SearchResults extends ImmutablePureComponent { static propTypes = { + value: ImmutablePropTypes.string, results: ImmutablePropTypes.map.isRequired, submitted: PropTypes.bool, expandSearch: PropTypes.func.isRequired, @@ -29,7 +31,7 @@ export default class SearchResults extends ImmutablePureComponent { }; render() { - const { results, submitted } = this.props; + const { value, results, submitted } = this.props; const { selectedFilter } = this.state; if (submitted && results.isEmpty()) { @@ -43,33 +45,57 @@ export default class SearchResults extends ImmutablePureComponent { let searchResults; let hasMore = false; - if (selectedFilter === 'accounts' && results.get('accounts') && results.get('accounts').size > 0) { + if (selectedFilter === 'accounts' && results.get('accounts')) { hasMore = results.get('accountsHasMore'); - searchResults = ( + searchResults = results.get('accounts').size > 0 ? (
{results.get('accounts').map(accountId => )}
- ); - } - - if (selectedFilter === 'statuses' && results.get('statuses') && results.get('statuses').size > 0) { - hasMore = results.get('statusesHasMore'); - - searchResults = ( -
- {results.get('statuses').map(statusId => )} + ) : ( +
+
); } - if (selectedFilter === 'hashtags' && results.get('hashtags') && results.get('hashtags').size > 0) { + if (selectedFilter === 'statuses' && results.get('statuses')) { + hasMore = results.get('statusesHasMore'); + + searchResults = results.get('statuses').size > 0 ? ( +
+ {results.get('statuses').map(statusId => )} +
+ ) : ( +
+ +
+ ); + } + + if (selectedFilter === 'hashtags' && results.get('hashtags')) { hasMore = results.get('hashtagsHasMore'); - searchResults = ( + searchResults = results.get('hashtags').size > 0 ? (
{results.get('hashtags').map(hashtag => )}
+ ) : ( +
+ +
); } diff --git a/app/soapbox/features/compose/containers/search_results_container.js b/app/soapbox/features/compose/containers/search_results_container.js index 734612dce..de61196d9 100644 --- a/app/soapbox/features/compose/containers/search_results_container.js +++ b/app/soapbox/features/compose/containers/search_results_container.js @@ -5,6 +5,7 @@ import { expandSearch } from '../../../actions/search'; const mapStateToProps = state => { return { + value: state.getIn(['search', 'submittedValue']), results: state.getIn(['search', 'results']), suggestions: state.getIn(['suggestions', 'items']), submitted: state.getIn(['search', 'submitted']), diff --git a/app/soapbox/reducers/__tests__/search-test.js b/app/soapbox/reducers/__tests__/search-test.js index fb74f1473..f09c4366f 100644 --- a/app/soapbox/reducers/__tests__/search-test.js +++ b/app/soapbox/reducers/__tests__/search-test.js @@ -6,6 +6,7 @@ describe('search reducer', () => { expect(reducer(undefined, {})).toEqual(ImmutableMap({ value: '', submitted: false, + submittedValue: '', hidden: false, results: ImmutableMap(), })); diff --git a/app/soapbox/reducers/search.js b/app/soapbox/reducers/search.js index c9ad6bfa8..c7c308967 100644 --- a/app/soapbox/reducers/search.js +++ b/app/soapbox/reducers/search.js @@ -16,6 +16,7 @@ import { Map as ImmutableMap, List as ImmutableList, fromJS } from 'immutable'; const initialState = ImmutableMap({ value: '', submitted: false, + submittedValue: '', hidden: false, results: ImmutableMap(), }); @@ -44,6 +45,7 @@ export default function search(state = initialState, action) { return state.withMutations(map => { map.set('results', ImmutableMap()); map.set('submitted', true); + map.set('submittedValue', action.value); }); case SEARCH_FETCH_SUCCESS: return state.set('results', ImmutableMap({ From f5edfbec1cdbfcc4f81d22150e7fb108d88cf6e9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?marcin=20miko=C5=82ajczak?= Date: Sat, 7 Aug 2021 20:59:11 +0200 Subject: [PATCH 2/2] Polish translation MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: marcin mikołajczak --- app/soapbox/locales/pl.json | 3 +++ 1 file changed, 3 insertions(+) diff --git a/app/soapbox/locales/pl.json b/app/soapbox/locales/pl.json index 6080d54af..e74f85e80 100644 --- a/app/soapbox/locales/pl.json +++ b/app/soapbox/locales/pl.json @@ -326,6 +326,9 @@ "empty_column.public": "Tu nic nie ma! Napisz coś publicznie, lub dodaj ludzi z innych serwerów, aby to wyświetlić", "empty_column.remote": "Tu nic nie ma! Zaobserwuj użytkowników {instance}, aby wypełnić tę oś.", "empty_column.scheduled_statuses": "Nie masz żadnych zaplanowanych wpisów. Kiedy dodasz jakiś, pojawi się on tutaj.", + "empty_column.search.accounts": "Brak wyników wyszukiwania osób dla „{term}”", + "empty_column.search.hashtags": "Brak wyników wyszukiwania hashtagów dla „{term}”", + "empty_column.search.statuses": "Brak wyników wyszukiwania wpisów dla „{term}”", "federation_restriction.federated_timeline_removal": "Usunięcie z osi czasu Fediwersum", "federation_restriction.followers_only": "Ukryte z wyjątkiem obserwujących", "federation_restriction.full_media_removal": "Pełne usunięcie mediów",