Merge pull request #2655 from TheEssem/fix/open-in

Use upstream's openURL function for search
This commit is contained in:
Claire 2024-02-29 18:23:56 +01:00 committed by GitHub
commit 8dbdd7571f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -143,11 +143,14 @@ export const showSearch = () => ({
type: SEARCH_SHOW, type: SEARCH_SHOW,
}); });
export const openURL = routerHistory => (dispatch, getState) => { export const openURL = (value, history, onFailure) => (dispatch, getState) => {
const value = getState().getIn(['search', 'value']);
const signedIn = !!getState().getIn(['meta', 'me']); const signedIn = !!getState().getIn(['meta', 'me']);
if (!signedIn) { if (!signedIn) {
if (onFailure) {
onFailure();
}
return; return;
} }
@ -156,15 +159,21 @@ export const openURL = routerHistory => (dispatch, getState) => {
api(getState).get('/api/v2/search', { params: { q: value, resolve: true } }).then(response => { api(getState).get('/api/v2/search', { params: { q: value, resolve: true } }).then(response => {
if (response.data.accounts?.length > 0) { if (response.data.accounts?.length > 0) {
dispatch(importFetchedAccounts(response.data.accounts)); dispatch(importFetchedAccounts(response.data.accounts));
routerHistory.push(`/@${response.data.accounts[0].acct}`); history.push(`/@${response.data.accounts[0].acct}`);
} else if (response.data.statuses?.length > 0) { } else if (response.data.statuses?.length > 0) {
dispatch(importFetchedStatuses(response.data.statuses)); dispatch(importFetchedStatuses(response.data.statuses));
routerHistory.push(`/@${response.data.statuses[0].account.acct}/${response.data.statuses[0].id}`); history.push(`/@${response.data.statuses[0].account.acct}/${response.data.statuses[0].id}`);
} else if (onFailure) {
onFailure();
} }
dispatch(fetchSearchSuccess(response.data, value)); dispatch(fetchSearchSuccess(response.data, value));
}).catch(err => { }).catch(err => {
dispatch(fetchSearchFail(err)); dispatch(fetchSearchFail(err));
if (onFailure) {
onFailure();
}
}); });
}; };