mirror of
https://github.com/cheeaun/phanpy.git
synced 2024-11-23 09:45:46 +03:00
New AccountBlock component
This commit is contained in:
parent
25ff2b9176
commit
ac30963ddf
4 changed files with 90 additions and 12 deletions
14
src/components/account-block.css
Normal file
14
src/components/account-block.css
Normal file
|
@ -0,0 +1,14 @@
|
|||
.account-block {
|
||||
display: flex;
|
||||
align-items: center;
|
||||
gap: 8px;
|
||||
color: var(--text-color);
|
||||
text-decoration: none;
|
||||
}
|
||||
.account-block:hover b {
|
||||
text-decoration: underline;
|
||||
}
|
||||
|
||||
.account-block.skeleton {
|
||||
color: var(--bg-faded-color);
|
||||
}
|
66
src/components/account-block.jsx
Normal file
66
src/components/account-block.jsx
Normal file
|
@ -0,0 +1,66 @@
|
|||
import './account-block.css';
|
||||
|
||||
import emojifyText from '../utils/emojify-text';
|
||||
import states from '../utils/states';
|
||||
|
||||
import Avatar from './avatar';
|
||||
|
||||
function AccountBlock({
|
||||
skeleton,
|
||||
account,
|
||||
avatarSize = 'xl',
|
||||
instance,
|
||||
external,
|
||||
onClick,
|
||||
}) {
|
||||
if (skeleton) {
|
||||
return (
|
||||
<div class="account-block skeleton">
|
||||
<Avatar size={avatarSize} />
|
||||
<span>
|
||||
<b>████████</b>
|
||||
<br />
|
||||
@██████
|
||||
</span>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
const { acct, avatar, avatarStatic, displayName, username, emojis, url } =
|
||||
account;
|
||||
const displayNameWithEmoji = emojifyText(displayName, emojis);
|
||||
|
||||
return (
|
||||
<a
|
||||
class="account-block"
|
||||
href={url}
|
||||
target={external ? '_blank' : null}
|
||||
title={`@${acct}`}
|
||||
onClick={(e) => {
|
||||
if (external) return;
|
||||
e.preventDefault();
|
||||
if (onClick) return onClick(e);
|
||||
states.showAccount = {
|
||||
account,
|
||||
instance,
|
||||
};
|
||||
}}
|
||||
>
|
||||
<Avatar url={avatar} size={avatarSize} />
|
||||
<span>
|
||||
{displayName ? (
|
||||
<b
|
||||
dangerouslySetInnerHTML={{
|
||||
__html: displayNameWithEmoji,
|
||||
}}
|
||||
/>
|
||||
) : (
|
||||
<b>{username}</b>
|
||||
)}
|
||||
<br />@{acct}
|
||||
</span>
|
||||
</a>
|
||||
);
|
||||
}
|
||||
|
||||
export default AccountBlock;
|
|
@ -10,10 +10,10 @@ import shortenNumber from '../utils/shorten-number';
|
|||
import states, { hideAllModals } from '../utils/states';
|
||||
import store from '../utils/store';
|
||||
|
||||
import AccountBlock from './account-block';
|
||||
import Avatar from './avatar';
|
||||
import Icon from './icon';
|
||||
import Link from './link';
|
||||
import NameText from './name-text';
|
||||
|
||||
function Account({ account, instance: propInstance, onClose }) {
|
||||
const { masto, instance, authenticated } = api({ instance: propInstance });
|
||||
|
@ -158,8 +158,7 @@ function Account({ account, instance: propInstance, onClose }) {
|
|||
{uiState === 'loading' ? (
|
||||
<>
|
||||
<header>
|
||||
<Avatar size="xxxl" />
|
||||
███ ████████████
|
||||
<AccountBlock avatarSize="xxxl" skeleton />
|
||||
</header>
|
||||
<main>
|
||||
<div class="note">
|
||||
|
@ -177,8 +176,12 @@ function Account({ account, instance: propInstance, onClose }) {
|
|||
info && (
|
||||
<>
|
||||
<header>
|
||||
<Avatar url={avatar} size="xxxl" />
|
||||
<NameText account={info} instance={instance} showAcct external />
|
||||
<AccountBlock
|
||||
account={info}
|
||||
instance={instance}
|
||||
avatarSize="xxxl"
|
||||
external
|
||||
/>
|
||||
</header>
|
||||
<main tabIndex="-1">
|
||||
{bot && (
|
||||
|
|
|
@ -3,6 +3,7 @@ import './search.css';
|
|||
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||
import { useSearchParams } from 'react-router-dom';
|
||||
|
||||
import AccountBlock from '../components/account-block';
|
||||
import Avatar from '../components/avatar';
|
||||
import Icon from '../components/icon';
|
||||
import Link from '../components/link';
|
||||
|
@ -87,13 +88,7 @@ function Search() {
|
|||
<ul class="timeline flat accounts-list">
|
||||
{accountResults.map((account) => (
|
||||
<li>
|
||||
<Avatar url={account.avatar} size="xl" />
|
||||
<NameText
|
||||
account={account}
|
||||
instance={instance}
|
||||
showAcct
|
||||
/>
|
||||
<br />
|
||||
<AccountBlock account={account} instance={instance} />
|
||||
</li>
|
||||
))}
|
||||
</ul>
|
||||
|
|
Loading…
Reference in a new issue