Skip to content

Commit

Permalink
enhance: Improve user mention
Browse files Browse the repository at this point in the history
  • Loading branch information
null2264 committed Oct 21, 2023
1 parent aa32822 commit 84e234b
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 21 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,8 @@
-->

## 2023.10.4
- UX: fetch account when mention component is rendering
- UX: "missing" account now show missing image icon as avatar next to user mention

## 2023.10.3
- UI: highlight mentions
Expand Down
35 changes: 14 additions & 21 deletions src/soapbox/components/mention.tsx
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import clsx from 'clsx';
import React from 'react';
import React, { useLayoutEffect } from 'react';
import { Link } from 'react-router-dom';

import { useAppSelector } from 'soapbox/hooks';
import { fetchAccount, fetchAccountByUsername } from 'soapbox/actions/accounts';
import { useAppSelector, useAppDispatch } from 'soapbox/hooks';
import { makeGetAccount } from 'soapbox/selectors';

import HoverRefWrapper from './hover-ref-wrapper';
Expand All @@ -17,27 +17,20 @@ export interface IMention {
}

export const Mention: React.FC<IMention> = ({ mention }) => {
const account = useAppSelector(state => mention.id !== '' ? getAccount(state, mention.id) : null);
const dispatch = useAppDispatch();
const getchAccount = () => {
if (mention.id !== '') dispatch(fetchAccount(mention.id));
dispatch(fetchAccountByUsername(mention.acct));
};
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 common = 'mention inline-block rounded-full bg-primary-200 text-primary-600 dark:bg-primary-800 dark:text-primary-400';

if (!account)
return (
<Link onClick={e => e.stopPropagation()} to={`/@${mention.acct}`} title={`@${mention.acct}`} className={clsx(common, 'px-2 py-1')}>
{mention.id !== '' ? (
<HoverRefWrapper key={mention.id} accountId={mention.id} className='inline-flex items-center align-top'>
@{mention.acct}
</HoverRefWrapper>
) : (
<>
@{mention.acct}
</>
)}
</Link>
);

useLayoutEffect(() => {
getchAccount();
}, []);

return (
<Link onClick={e => e.stopPropagation()} to={`/@${account.acct}`} title={`@${account.fqn}`} className={clsx(common, 'py-1 pl-1 pr-2')}>
<Link onClick={e => e.stopPropagation()} to={`/@${account.acct}`} title={`@${account.fqn}`} className='mention inline-block rounded-full bg-primary-200 py-1 pl-1 pr-2 text-primary-600 dark:bg-primary-800 dark:text-primary-400'>
<HoverRefWrapper key={account.id} accountId={account.id} className='inline-flex items-center align-top'>
<Avatar size={avatarSize} src={account.avatar} className='mr-1.5 inline-flex items-center align-bottom' />
<span>@{account.acct}</span>
Expand Down

0 comments on commit 84e234b

Please sign in to comment.