Skip to content

Commit

Permalink
Merge pull request #2655 from TheEssem/fix/open-in
Browse files Browse the repository at this point in the history
Use upstream's openURL function for search
  • Loading branch information
ClearlyClaire authored Feb 29, 2024
2 parents fd2e468 + 9242c53 commit 8dbdd75
Showing 1 changed file with 13 additions and 4 deletions.
17 changes: 13 additions & 4 deletions app/javascript/flavours/glitch/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -143,11 +143,14 @@ export const showSearch = () => ({
type: SEARCH_SHOW,
});

export const openURL = routerHistory => (dispatch, getState) => {
const value = getState().getIn(['search', 'value']);
export const openURL = (value, history, onFailure) => (dispatch, getState) => {
const signedIn = !!getState().getIn(['meta', 'me']);

if (!signedIn) {
if (onFailure) {
onFailure();
}

return;
}

Expand All @@ -156,15 +159,21 @@ export const openURL = routerHistory => (dispatch, getState) => {
api(getState).get('/api/v2/search', { params: { q: value, resolve: true } }).then(response => {
if (response.data.accounts?.length > 0) {
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) {
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));
}).catch(err => {
dispatch(fetchSearchFail(err));

if (onFailure) {
onFailure();
}
});
};

Expand Down

0 comments on commit 8dbdd75

Please sign in to comment.