Skip to content

Commit

Permalink
Port search popout changes from upstream (#2333)
Browse files Browse the repository at this point in the history
* [Glitch] Change search pop-out in web UI

Port 2b11376 to glitch-soc

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

* [Glitch] Change logo version in header based on screen size in web UI

Port remaining change from 6028d04 to glitch-soc

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

* Rename `hashtags.js` to `hashtags.ts` and apply code style changes

Apply changes from e38b391 (rename to ts), 51b83ed (code style change), 73b64b8 (additional code style change)

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

* Remove strings for old search

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>

---------

Signed-off-by: Plastikmensch <plastikmensch@users.noreply.github.com>
  • Loading branch information
Plastikmensch authored Jul 30, 2023
1 parent 3a14104 commit ebfa184
Show file tree
Hide file tree
Showing 12 changed files with 421 additions and 93 deletions.
45 changes: 44 additions & 1 deletion app/javascript/flavours/glitch/actions/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,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 @@ -28,7 +31,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 @@ -45,6 +48,7 @@ export function submitSearch() {
q: value,
resolve: signedIn,
limit: 10,
type,
},
}).then(response => {
if (response.data.accounts) {
Expand Down Expand Up @@ -131,3 +135,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,
});
Loading

0 comments on commit ebfa184

Please sign in to comment.