Skip to content

Commit

Permalink
Change search to use query params in web UI (mastodon#32949)
Browse files Browse the repository at this point in the history
  • Loading branch information
Gargron authored Dec 12, 2024
1 parent 708919e commit 0636bcd
Show file tree
Hide file tree
Showing 28 changed files with 1,396 additions and 1,270 deletions.
24 changes: 18 additions & 6 deletions app/javascript/hooks/useLinks.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@ import { useCallback } from 'react';

import { useHistory } from 'react-router-dom';

import { isFulfilled, isRejected } from '@reduxjs/toolkit';

import { openURL } from 'mastodon/actions/search';
import { useAppDispatch } from 'mastodon/store';

Expand All @@ -28,12 +30,22 @@ export const useLinks = () => {
);

const handleMentionClick = useCallback(
(element: HTMLAnchorElement) => {
dispatch(
openURL(element.href, history, () => {
async (element: HTMLAnchorElement) => {
const result = await dispatch(openURL({ url: element.href }));

if (isFulfilled(result)) {
if (result.payload.accounts[0]) {
history.push(`/@${result.payload.accounts[0].acct}`);
} else if (result.payload.statuses[0]) {
history.push(
`/@${result.payload.statuses[0].account.acct}/${result.payload.statuses[0].id}`,
);
} else {
window.location.href = element.href;
}),
);
}
} else if (isRejected(result)) {
window.location.href = element.href;
}
},
[dispatch, history],
);
Expand All @@ -48,7 +60,7 @@ export const useLinks = () => {

if (isMentionClick(target)) {
e.preventDefault();
handleMentionClick(target);
void handleMentionClick(target);
} else if (isHashtagClick(target)) {
e.preventDefault();
handleHashtagClick(target);
Expand Down
215 changes: 0 additions & 215 deletions app/javascript/mastodon/actions/search.js

This file was deleted.

Loading

0 comments on commit 0636bcd

Please sign in to comment.