Skip to content

Commit

Permalink
enhance: Adjust avatar size depends on text size
Browse files Browse the repository at this point in the history
(kinda)
  • Loading branch information
null2264 committed Oct 22, 2023
1 parent 53fe0b3 commit 133157e
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 4 deletions.
6 changes: 4 additions & 2 deletions src/soapbox/components/mention.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -8,21 +8,23 @@ import { makeGetAccount } from 'soapbox/selectors';
import HoverRefWrapper from './hover-ref-wrapper';
import { Avatar } from './ui';

import type { Sizes } from 'soapbox/components/ui/text/text';
import type { Mention as MentionEntity } from 'soapbox/schemas';

const getAccount = makeGetAccount();

export interface IMention {
mention: MentionEntity
textSize?: Sizes
}

export const Mention: React.FC<IMention> = ({ mention }) => {
export const Mention: React.FC<IMention> = ({ mention, textSize = 'md' }) => {
const dispatch = useAppDispatch();
const getchAccount = () => {
if (mention.id !== '') dispatch(fetchAccount(mention.id));
};
const account: any = useAppSelector(state => ((mention.id !== '') ? getAccount(state, mention.id) : null) || { id: mention.id, fqn: mention.acct, acct: mention.acct, url: mention.url, username: mention.username, avatar: '' });
const avatarSize = 20;
const avatarSize = textSize === 'lg' ? 28 : 20;

useLayoutEffect(() => {
getchAccount();
Expand Down
4 changes: 2 additions & 2 deletions src/soapbox/components/status-content.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -86,13 +86,13 @@ const StatusContent: React.FC<IStatusContent> = ({
if (classes.includes('mention')) {
const mention: MentionEntity | undefined = status.mentions.find(({ url }) => node.attribs.href === url);
if (mention) {
return (<Mention mention={mention} />);
return (<Mention mention={mention} textSize={textSize} />);
} else if (node.attribs.href) {
// User is not present in database, construct acct from url
const matches = [...node.attribs.href.matchAll(/^http(?:s)?:\/\/((?:[a-z0-9]+(-[a-z0-9]+)*\.)+[a-z]{2,})\/(?:@|users?\/)(\S+)/gm)][0];

if (matches) {
return (<Mention mention={{ acct: `${matches[3]}@${matches[1]}`, url: node.attribs.href, id: '', username: '' }} />);
return (<Mention mention={{ acct: `${matches[3]}@${matches[1]}`, url: node.attribs.href, id: '', username: '' }} textSize={textSize} />);
}
}
}
Expand Down

0 comments on commit 133157e

Please sign in to comment.