Emoji: Account page (#36385)

This commit is contained in:
Echo 2025-10-08 13:11:25 +02:00 committed by GitHub
commit 6abda76d13
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
10 changed files with 195 additions and 137 deletions

View file

@ -1,7 +1,10 @@
import { useCallback } from 'react';
import type { ComponentProps, FC } from 'react';
import { Link } from 'react-router-dom';
import type { OnElementHandler } from '@/mastodon/utils/html';
export interface HandledLinkProps {
href: string;
text: string;
@ -77,3 +80,31 @@ export const HandledLink: FC<HandledLinkProps & ComponentProps<'a'>> = ({
return text;
}
};
export const useElementHandledLink = ({
hashtagAccountId,
mentionAccountId,
}: {
hashtagAccountId?: string;
mentionAccountId?: string;
} = {}) => {
const onElement = useCallback<OnElementHandler>(
(element, { key, ...props }) => {
if (element instanceof HTMLAnchorElement) {
return (
<HandledLink
{...props}
key={key as string} // React requires keys to not be part of spread props.
href={element.href}
text={element.innerText}
hashtagAccountId={hashtagAccountId}
mentionAccountId={mentionAccountId}
/>
);
}
return undefined;
},
[hashtagAccountId, mentionAccountId],
);
return { onElement };
};