kopia lustrzana https://gitlab.com/soapbox-pub/soapbox
Merge branch 'clear-search-behavior' into 'develop'
Do not reset tab/searched account when clearing search input See merge request soapbox-pub/soapbox!1781environments/review-develop-3zknud/deployments/924
commit
a394fe1ced
|
@ -8,9 +8,10 @@ import type { SearchFilter } from 'soapbox/reducers/search';
|
||||||
import type { AppDispatch, RootState } from 'soapbox/store';
|
import type { AppDispatch, RootState } from 'soapbox/store';
|
||||||
import type { APIEntity } from 'soapbox/types/entities';
|
import type { APIEntity } from 'soapbox/types/entities';
|
||||||
|
|
||||||
const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
const SEARCH_CHANGE = 'SEARCH_CHANGE';
|
||||||
const SEARCH_CLEAR = 'SEARCH_CLEAR';
|
const SEARCH_CLEAR = 'SEARCH_CLEAR';
|
||||||
const SEARCH_SHOW = 'SEARCH_SHOW';
|
const SEARCH_SHOW = 'SEARCH_SHOW';
|
||||||
|
const SEARCH_RESULTS_CLEAR = 'SEARCH_RESULTS_CLEAR';
|
||||||
|
|
||||||
const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST';
|
const SEARCH_FETCH_REQUEST = 'SEARCH_FETCH_REQUEST';
|
||||||
const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS';
|
const SEARCH_FETCH_SUCCESS = 'SEARCH_FETCH_SUCCESS';
|
||||||
|
@ -28,7 +29,11 @@ const changeSearch = (value: string) =>
|
||||||
(dispatch: AppDispatch) => {
|
(dispatch: AppDispatch) => {
|
||||||
// If backspaced all the way, clear the search
|
// If backspaced all the way, clear the search
|
||||||
if (value.length === 0) {
|
if (value.length === 0) {
|
||||||
return dispatch(clearSearch());
|
dispatch(clearSearchResults());
|
||||||
|
return dispatch({
|
||||||
|
type: SEARCH_CHANGE,
|
||||||
|
value,
|
||||||
|
});
|
||||||
} else {
|
} else {
|
||||||
return dispatch({
|
return dispatch({
|
||||||
type: SEARCH_CHANGE,
|
type: SEARCH_CHANGE,
|
||||||
|
@ -41,6 +46,10 @@ const clearSearch = () => ({
|
||||||
type: SEARCH_CLEAR,
|
type: SEARCH_CLEAR,
|
||||||
});
|
});
|
||||||
|
|
||||||
|
const clearSearchResults = () => ({
|
||||||
|
type: SEARCH_RESULTS_CLEAR,
|
||||||
|
});
|
||||||
|
|
||||||
const submitSearch = (filter?: SearchFilter) =>
|
const submitSearch = (filter?: SearchFilter) =>
|
||||||
(dispatch: AppDispatch, getState: () => RootState) => {
|
(dispatch: AppDispatch, getState: () => RootState) => {
|
||||||
const value = getState().search.value;
|
const value = getState().search.value;
|
||||||
|
@ -167,6 +176,7 @@ export {
|
||||||
SEARCH_CHANGE,
|
SEARCH_CHANGE,
|
||||||
SEARCH_CLEAR,
|
SEARCH_CLEAR,
|
||||||
SEARCH_SHOW,
|
SEARCH_SHOW,
|
||||||
|
SEARCH_RESULTS_CLEAR,
|
||||||
SEARCH_FETCH_REQUEST,
|
SEARCH_FETCH_REQUEST,
|
||||||
SEARCH_FETCH_SUCCESS,
|
SEARCH_FETCH_SUCCESS,
|
||||||
SEARCH_FETCH_FAIL,
|
SEARCH_FETCH_FAIL,
|
||||||
|
@ -177,6 +187,7 @@ export {
|
||||||
SEARCH_ACCOUNT_SET,
|
SEARCH_ACCOUNT_SET,
|
||||||
changeSearch,
|
changeSearch,
|
||||||
clearSearch,
|
clearSearch,
|
||||||
|
clearSearchResults,
|
||||||
submitSearch,
|
submitSearch,
|
||||||
fetchSearchRequest,
|
fetchSearchRequest,
|
||||||
fetchSearchSuccess,
|
fetchSearchSuccess,
|
||||||
|
|
|
@ -9,6 +9,7 @@ import { useHistory } from 'react-router-dom';
|
||||||
import {
|
import {
|
||||||
changeSearch,
|
changeSearch,
|
||||||
clearSearch,
|
clearSearch,
|
||||||
|
clearSearchResults,
|
||||||
setSearchAccount,
|
setSearchAccount,
|
||||||
showSearch,
|
showSearch,
|
||||||
submitSearch,
|
submitSearch,
|
||||||
|
@ -72,7 +73,7 @@ const Search = (props: ISearch) => {
|
||||||
event.preventDefault();
|
event.preventDefault();
|
||||||
|
|
||||||
if (value.length > 0 || submitted) {
|
if (value.length > 0 || submitted) {
|
||||||
dispatch(clearSearch());
|
dispatch(clearSearchResults());
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -2,7 +2,7 @@ import classNames from 'clsx';
|
||||||
import React, { useEffect, useRef } from 'react';
|
import React, { useEffect, useRef } from 'react';
|
||||||
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
import { FormattedMessage, defineMessages, useIntl } from 'react-intl';
|
||||||
|
|
||||||
import { clearSearch, expandSearch, setFilter } from 'soapbox/actions/search';
|
import { expandSearch, setFilter, setSearchAccount } from 'soapbox/actions/search';
|
||||||
import { fetchTrendingStatuses } from 'soapbox/actions/trending_statuses';
|
import { fetchTrendingStatuses } from 'soapbox/actions/trending_statuses';
|
||||||
import Hashtag from 'soapbox/components/hashtag';
|
import Hashtag from 'soapbox/components/hashtag';
|
||||||
import IconButton from 'soapbox/components/icon_button';
|
import IconButton from 'soapbox/components/icon_button';
|
||||||
|
@ -43,7 +43,7 @@ const SearchResults = () => {
|
||||||
|
|
||||||
const handleLoadMore = () => dispatch(expandSearch(selectedFilter));
|
const handleLoadMore = () => dispatch(expandSearch(selectedFilter));
|
||||||
|
|
||||||
const handleClearSearch = () => dispatch(clearSearch());
|
const handleUnsetAccount = () => dispatch(setSearchAccount(null));
|
||||||
|
|
||||||
const selectFilter = (newActiveFilter: SearchFilter) => dispatch(setFilter(newActiveFilter));
|
const selectFilter = (newActiveFilter: SearchFilter) => dispatch(setFilter(newActiveFilter));
|
||||||
|
|
||||||
|
@ -196,7 +196,7 @@ const SearchResults = () => {
|
||||||
<>
|
<>
|
||||||
{filterByAccount ? (
|
{filterByAccount ? (
|
||||||
<HStack className='mb-4 pb-4 px-2 border-solid border-b border-gray-200 dark:border-gray-800' space={2}>
|
<HStack className='mb-4 pb-4 px-2 border-solid border-b border-gray-200 dark:border-gray-800' space={2}>
|
||||||
<IconButton iconClassName='h-5 w-5' src={require('@tabler/icons/x.svg')} onClick={handleClearSearch} />
|
<IconButton iconClassName='h-5 w-5' src={require('@tabler/icons/x.svg')} onClick={handleUnsetAccount} />
|
||||||
<Text>
|
<Text>
|
||||||
<FormattedMessage
|
<FormattedMessage
|
||||||
id='search_results.filter_message'
|
id='search_results.filter_message'
|
||||||
|
|
|
@ -18,6 +18,7 @@ import {
|
||||||
SEARCH_EXPAND_REQUEST,
|
SEARCH_EXPAND_REQUEST,
|
||||||
SEARCH_EXPAND_SUCCESS,
|
SEARCH_EXPAND_SUCCESS,
|
||||||
SEARCH_ACCOUNT_SET,
|
SEARCH_ACCOUNT_SET,
|
||||||
|
SEARCH_RESULTS_CLEAR,
|
||||||
} from '../actions/search';
|
} from '../actions/search';
|
||||||
|
|
||||||
import type { AnyAction } from 'redux';
|
import type { AnyAction } from 'redux';
|
||||||
|
@ -105,6 +106,13 @@ export default function search(state = ReducerRecord(), action: AnyAction) {
|
||||||
return state.set('value', action.value);
|
return state.set('value', action.value);
|
||||||
case SEARCH_CLEAR:
|
case SEARCH_CLEAR:
|
||||||
return ReducerRecord();
|
return ReducerRecord();
|
||||||
|
case SEARCH_RESULTS_CLEAR:
|
||||||
|
return state.merge({
|
||||||
|
value: '',
|
||||||
|
results: ResultsRecord(),
|
||||||
|
submitted: false,
|
||||||
|
submittedValue: '',
|
||||||
|
});
|
||||||
case SEARCH_SHOW:
|
case SEARCH_SHOW:
|
||||||
return state.set('hidden', false);
|
return state.set('hidden', false);
|
||||||
case COMPOSE_REPLY:
|
case COMPOSE_REPLY:
|
||||||
|
@ -123,7 +131,13 @@ export default function search(state = ReducerRecord(), action: AnyAction) {
|
||||||
case SEARCH_EXPAND_SUCCESS:
|
case SEARCH_EXPAND_SUCCESS:
|
||||||
return paginateResults(state, action.searchType, action.results, action.searchTerm);
|
return paginateResults(state, action.searchType, action.results, action.searchTerm);
|
||||||
case SEARCH_ACCOUNT_SET:
|
case SEARCH_ACCOUNT_SET:
|
||||||
if (!action.accountId) return state.set('accountId', null);
|
if (!action.accountId) return state.merge({
|
||||||
|
results: ResultsRecord(),
|
||||||
|
submitted: false,
|
||||||
|
submittedValue: '',
|
||||||
|
filter: 'accounts',
|
||||||
|
accountId: null,
|
||||||
|
});
|
||||||
return ReducerRecord({ accountId: action.accountId, filter: 'statuses' });
|
return ReducerRecord({ accountId: action.accountId, filter: 'statuses' });
|
||||||
default:
|
default:
|
||||||
return state;
|
return state;
|
||||||
|
|
Ładowanie…
Reference in New Issue