pl-fe: nyaize & ParsedContent component cleanup
Signed-off-by: mkljczk <git@mkljczk.pl>
This commit is contained in:
@ -29,7 +29,7 @@ const guessFqn = (account: Pick<Account, 'acct' | 'url'>): string => {
|
||||
const filterBadges = (tags?: string[]) =>
|
||||
tags?.filter(tag => tag.startsWith('badge:')).map(tag => v.parse(roleSchema, { id: tag, name: tag.replace(/^badge:/, '') }));
|
||||
|
||||
const MKLJCZK_ACCOUNTS = ['https://pl.fediverse.pl/users/mkljczk', 'https://gts.mkljczk.pl/users/mkljczk'];
|
||||
const MKLJCZK_ACCOUNTS = ['https://pl.fediverse.pl/users/mkljczk', 'https://gts.mkljczk.pl/users/mkljczk', 'https://gts.mkljczk.pl/@mkljczk'];
|
||||
|
||||
const preprocessAccount = v.transform((account: any) => {
|
||||
if (!account?.acct) return null;
|
||||
|
||||
@ -349,7 +349,7 @@ const Account = ({
|
||||
size='sm'
|
||||
className='line-clamp-2 inline text-ellipsis [&_br]:hidden [&_p:first-child]:inline [&_p:first-child]:truncate [&_p]:hidden'
|
||||
>
|
||||
<ParsedContent html={account.note} emojis={account.emojis} />
|
||||
<ParsedContent html={account.note} emojis={account.emojis} speakAsCat={account.speak_as_cat} />
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@ -30,6 +30,9 @@ interface IParsedContent {
|
||||
hasQuote?: boolean;
|
||||
/** Related custom emojis. */
|
||||
emojis?: Array<CustomEmoji>;
|
||||
cleanUrls?: boolean;
|
||||
greentext?: boolean;
|
||||
speakAsCat?: boolean;
|
||||
}
|
||||
|
||||
// Adapted from Mastodon https://github.com/mastodon/mastodon/blob/main/app/javascript/mastodon/components/hashtag_bar.tsx
|
||||
@ -64,8 +67,8 @@ const uniqueHashtagsWithCaseHandling = (hashtags: string[]) => {
|
||||
});
|
||||
};
|
||||
|
||||
function parseContent(props: IParsedContent, extractHashtags?: false, cleanUrls?: boolean, greentext?: boolean, speakAsCat?: boolean): ReturnType<typeof domToReact>;
|
||||
function parseContent(props: IParsedContent, extractHashtags: true, cleanUrls: boolean, greentext: boolean, speakAsCat: boolean): {
|
||||
function parseContent(props: IParsedContent, extractHashtags?: false): ReturnType<typeof domToReact>;
|
||||
function parseContent(props: IParsedContent, extractHashtags: true): {
|
||||
hashtags: Array<string>;
|
||||
content: ReturnType<typeof domToReact>;
|
||||
};
|
||||
@ -75,7 +78,10 @@ function parseContent({
|
||||
mentions,
|
||||
hasQuote,
|
||||
emojis,
|
||||
}: IParsedContent, extractHashtags = false, cleanUrls = false, greentext = false, speakAsCat = false) {
|
||||
cleanUrls = false,
|
||||
greentext = false,
|
||||
speakAsCat = false,
|
||||
}: IParsedContent, extractHashtags = false) {
|
||||
if (html.length === 0) {
|
||||
return extractHashtags ? { content: null, hashtags: [] } : null;
|
||||
}
|
||||
@ -208,7 +214,11 @@ function parseContent({
|
||||
const ParsedContent: React.FC<IParsedContent> = React.memo((props) => {
|
||||
const settings = useSettings();
|
||||
|
||||
return parseContent(props, false, settings.urlPrivacy.clearLinksInContent, false, false);
|
||||
if (props.cleanUrls === undefined) {
|
||||
props = { ...props, cleanUrls: settings.urlPrivacy.clearLinksInContent };
|
||||
}
|
||||
|
||||
return parseContent(props, false);
|
||||
}, (prevProps, nextProps) => prevProps.html === nextProps.html);
|
||||
|
||||
export { ParsedContent, parseContent };
|
||||
|
||||
@ -146,7 +146,10 @@ const StatusContent: React.FC<IStatusContent> = React.memo(({
|
||||
mentions: status.mentions,
|
||||
hasQuote: !!status.quote_id,
|
||||
emojis: status.emojis,
|
||||
}, true, urlPrivacy.clearLinksInContent, greentext, status.account.speak_as_cat), [content]);
|
||||
cleanUrls: urlPrivacy.clearLinksInContent,
|
||||
greentext,
|
||||
speakAsCat: status.account.speak_as_cat,
|
||||
}, true), [content]);
|
||||
|
||||
useEffect(() => {
|
||||
setLineClamp(!spoilerNode.current || spoilerNode.current.clientHeight >= 96);
|
||||
|
||||
@ -48,7 +48,7 @@ const Announcement: React.FC<IAnnouncement> = ({ announcement }) => {
|
||||
|
||||
return (
|
||||
<div key={announcement.id} className='rounded-lg bg-gray-100 p-4 dark:bg-primary-800'>
|
||||
<Stack space={2}>
|
||||
<Stack space={2}>n
|
||||
<Text>
|
||||
<ParsedContent html={announcement.content} emojis={announcement.emojis} />
|
||||
</Text>
|
||||
|
||||
@ -76,7 +76,7 @@ const AccountCard: React.FC<IAccountCard> = ({ id }) => {
|
||||
align='left'
|
||||
className='line-clamp-2 inline text-ellipsis [&_br]:hidden [&_p:first-child]:inline [&_p:first-child]:truncate [&_p]:hidden'
|
||||
>
|
||||
<ParsedContent html={account.note} emojis={account.emojis} />
|
||||
<ParsedContent html={account.note} emojis={account.emojis} speakAsCat={account.speak_as_cat} />
|
||||
</Text>
|
||||
)}
|
||||
</Stack>
|
||||
|
||||
@ -35,7 +35,7 @@ const CompareHistoryModal: React.FC<BaseModalProps & CompareHistoryModalProps> =
|
||||
body = (
|
||||
<div className='divide-y divide-solid divide-gray-200 dark:divide-gray-800'>
|
||||
{versions?.map((version) => {
|
||||
const content = <ParsedContent html={version.content} mentions={status?.mentions} hasQuote={!!status?.quote_id} emojis={version.emojis} />;
|
||||
const content = <ParsedContent html={version.content} mentions={status?.mentions} hasQuote={!!status?.quote_id} emojis={version.emojis} speakAsCat={status.account.speak_as_cat} />;
|
||||
|
||||
const poll = typeof version.poll !== 'string' && version.poll;
|
||||
|
||||
@ -66,7 +66,7 @@ const CompareHistoryModal: React.FC<BaseModalProps & CompareHistoryModalProps> =
|
||||
/>
|
||||
|
||||
<span>
|
||||
<ParsedContent html={option.title} emojis={version.emojis} />
|
||||
<ParsedContent html={option.title} emojis={version.emojis} speakAsCat={status.account.speak_as_cat} />
|
||||
</span>
|
||||
</HStack>
|
||||
))}
|
||||
|
||||
@ -168,7 +168,7 @@ const ProfileInfoPanel: React.FC<IProfileInfoPanel> = ({ account, username }) =>
|
||||
|
||||
{!!account.note && (
|
||||
<Markup size='sm'>
|
||||
<ParsedContent html={account.note} emojis={account.emojis} />
|
||||
<ParsedContent html={account.note} emojis={account.emojis} speakAsCat={account.speak_as_cat} />
|
||||
</Markup>
|
||||
)}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user