Emoji: Account page (#36385)
This commit is contained in:
10 files changed
+195
-137
No files matched your search
@@ -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 };
|
||||
};
|
||||
Reference in new issue
Block a user