Merge commit 'cfb473c204' into upstream-20250228

This commit is contained in:
KMY 2025-02-28 11:07:08 +09:00
commit 795561f5a7
78 changed files with 1684 additions and 1081 deletions

View file

@ -14,6 +14,9 @@ const isHashtagClick = (element: HTMLAnchorElement) =>
element.textContent?.[0] === '#' ||
element.previousSibling?.textContent?.endsWith('#');
const isFeaturedHashtagClick = (element: HTMLAnchorElement) =>
isHashtagClick(element) && element.href.includes('/tagged/');
export const useLinks = () => {
const history = useHistory();
const dispatch = useAppDispatch();
@ -29,6 +32,19 @@ export const useLinks = () => {
[history],
);
const handleFeaturedHashtagClick = useCallback(
(element: HTMLAnchorElement) => {
const { textContent, href } = element;
if (!textContent) return;
const url = new URL(href);
history.push(url.pathname);
},
[history],
);
const handleMentionClick = useCallback(
async (element: HTMLAnchorElement) => {
const result = await dispatch(openURL({ url: element.href }));
@ -61,12 +77,15 @@ export const useLinks = () => {
if (isMentionClick(target)) {
e.preventDefault();
void handleMentionClick(target);
} else if (isFeaturedHashtagClick(target)) {
e.preventDefault();
handleFeaturedHashtagClick(target);
} else if (isHashtagClick(target)) {
e.preventDefault();
handleHashtagClick(target);
}
},
[handleMentionClick, handleHashtagClick],
[handleMentionClick, handleFeaturedHashtagClick, handleHashtagClick],
);
return handleClick;