Emoji: Account page (#36385)
This commit is contained in:
parent
3867f3bc61
commit
6abda76d13
10 changed files with 195 additions and 137 deletions
|
|
@ -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 };
|
||||
};
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue