Merge branch 'search-bugfixes' into 'develop'

Search bugfixes

See merge request soapbox-pub/soapbox-fe!872
This commit is contained in:
Alex Gleason 2021-11-15 22:19:58 +00:00
commit 615cdc5c66
2 changed files with 24 additions and 26 deletions

View File

@ -17,9 +17,16 @@ export const SEARCH_EXPAND_SUCCESS = 'SEARCH_EXPAND_SUCCESS';
export const SEARCH_EXPAND_FAIL = 'SEARCH_EXPAND_FAIL'; export const SEARCH_EXPAND_FAIL = 'SEARCH_EXPAND_FAIL';
export function changeSearch(value) { export function changeSearch(value) {
return { return (dispatch, getState) => {
type: SEARCH_CHANGE, // If backspaced all the way, clear the search
value, if (value.length === 0) {
return dispatch(clearSearch());
} else {
return dispatch({
type: SEARCH_CHANGE,
value,
});
}
}; };
} }
@ -29,10 +36,11 @@ export function clearSearch() {
}; };
} }
export function submitSearch() { export function submitSearch(filter) {
return (dispatch, getState) => { return (dispatch, getState) => {
const value = getState().getIn(['search', 'value']); const value = getState().getIn(['search', 'value']);
// An empty search doesn't return any results
if (value.length === 0) { if (value.length === 0) {
return; return;
} }
@ -44,6 +52,7 @@ export function submitSearch() {
q: value, q: value,
resolve: true, resolve: true,
limit: 20, limit: 20,
type: filter || getState().getIn(['search', 'filter'], 'accounts'),
}, },
}).then(response => { }).then(response => {
if (response.data.accounts) { if (response.data.accounts) {
@ -83,13 +92,17 @@ export function fetchSearchFail(error) {
}; };
} }
export const setFilter = filterType => dispatch => { export function setFilter(filterType) {
dispatch({ return (dispatch) => {
type: SEARCH_FILTER_SET, dispatch(submitSearch(filterType));
path: ['search', 'filter'],
value: filterType, dispatch({
}); type: SEARCH_FILTER_SET,
}; path: ['search', 'filter'],
value: filterType,
});
};
}
export const expandSearch = type => (dispatch, getState) => { export const expandSearch = type => (dispatch, getState) => {
const value = getState().getIn(['search', 'value']); const value = getState().getIn(['search', 'value']);

View File

@ -28,21 +28,7 @@ const toIds = items => {
return ImmutableOrderedSet(items.map(item => item.id)); return ImmutableOrderedSet(items.map(item => item.id));
}; };
const getResultsFilter = results => {
if (results.accounts.length > 0) {
return 'accounts';
} else if (results.statuses.length > 0) {
return 'statuses';
} else if (results.hashtags.length > 0) {
return 'hashtags';
} else {
return 'accounts';
}
};
const importResults = (state, results) => { const importResults = (state, results) => {
const filter = getResultsFilter(results);
return state.withMutations(state => { return state.withMutations(state => {
state.set('results', ImmutableMap({ state.set('results', ImmutableMap({
accounts: toIds(results.accounts), accounts: toIds(results.accounts),
@ -57,7 +43,6 @@ const importResults = (state, results) => {
})); }));
state.set('submitted', true); state.set('submitted', true);
state.set('filter', filter);
}); });
}; };