Skip to content

Commit

Permalink
Change search pop-out in web UI
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron committed Mar 30, 2023
1 parent f318f1e commit 2217ef8
Show file tree
Hide file tree
Showing 10 changed files with 446 additions and 90 deletions.
45 changes: 44 additions & 1 deletion app/javascript/mastodon/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@ export const SEARCH_EXPAND_REQUEST = 'SEARCH_EXPAND_REQUEST';
export const SEARCH_EXPAND_SUCCESS = 'SEARCH_EXPAND_SUCCESS';
export const SEARCH_EXPAND_FAIL = 'SEARCH_EXPAND_FAIL';

export const SEARCH_RESULT_CLICK = 'SEARCH_RESULT_CLICK';
export const SEARCH_RESULT_FORGET = 'SEARCH_RESULT_FORGET';

export function changeSearch(value) {
return {
type: SEARCH_CHANGE,
Expand All @@ -27,7 +30,7 @@ export function clearSearch() {
};
}

export function submitSearch() {
export function submitSearch(type) {
return (dispatch, getState) => {
const value = getState().getIn(['search', 'value']);
const signedIn = !!getState().getIn(['meta', 'me']);
Expand All @@ -44,6 +47,7 @@ export function submitSearch() {
q: value,
resolve: signedIn,
limit: 5,
type,
},
}).then(response => {
if (response.data.accounts) {
Expand Down Expand Up @@ -130,3 +134,42 @@ export const expandSearchFail = error => ({
export const showSearch = () => ({
type: SEARCH_SHOW,
});

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

if (!signedIn) {
return;
}

dispatch(fetchSearchRequest());

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}`);
} 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}`);
}

dispatch(fetchSearchSuccess(response.data, value));
}).catch(err => {
dispatch(fetchSearchFail(err));
});
};

export const clickSearchResult = (q, type) => ({
type: SEARCH_RESULT_CLICK,

result: {
type,
q,
},
});

export const forgetSearchResult = q => ({
type: SEARCH_RESULT_FORGET,
q,
});

0 comments on commit 2217ef8

Please sign in to comment.