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

View File

@ -28,21 +28,7 @@ const toIds = items => {
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 filter = getResultsFilter(results);
return state.withMutations(state => {
state.set('results', ImmutableMap({
accounts: toIds(results.accounts),
@ -57,7 +43,6 @@ const importResults = (state, results) => {
}));
state.set('submitted', true);
state.set('filter', filter);
});
};