mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-02-17 07:41:35 +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 states, { hideAllModals } from '../utils/states';
|
||||||
import store from '../utils/store';
|
import store from '../utils/store';
|
||||||
|
|
||||||
|
import AccountBlock from './account-block';
|
||||||
import Avatar from './avatar';
|
import Avatar from './avatar';
|
||||||
import Icon from './icon';
|
import Icon from './icon';
|
||||||
import Link from './link';
|
import Link from './link';
|
||||||
import NameText from './name-text';
|
|
||||||
|
|
||||||
function Account({ account, instance: propInstance, onClose }) {
|
function Account({ account, instance: propInstance, onClose }) {
|
||||||
const { masto, instance, authenticated } = api({ instance: propInstance });
|
const { masto, instance, authenticated } = api({ instance: propInstance });
|
||||||
|
@ -158,8 +158,7 @@ function Account({ account, instance: propInstance, onClose }) {
|
||||||
{uiState === 'loading' ? (
|
{uiState === 'loading' ? (
|
||||||
<>
|
<>
|
||||||
<header>
|
<header>
|
||||||
<Avatar size="xxxl" />
|
<AccountBlock avatarSize="xxxl" skeleton />
|
||||||
███ ████████████
|
|
||||||
</header>
|
</header>
|
||||||
<main>
|
<main>
|
||||||
<div class="note">
|
<div class="note">
|
||||||
|
@ -177,8 +176,12 @@ function Account({ account, instance: propInstance, onClose }) {
|
||||||
info && (
|
info && (
|
||||||
<>
|
<>
|
||||||
<header>
|
<header>
|
||||||
<Avatar url={avatar} size="xxxl" />
|
<AccountBlock
|
||||||
<NameText account={info} instance={instance} showAcct external />
|
account={info}
|
||||||
|
instance={instance}
|
||||||
|
avatarSize="xxxl"
|
||||||
|
external
|
||||||
|
/>
|
||||||
</header>
|
</header>
|
||||||
<main tabIndex="-1">
|
<main tabIndex="-1">
|
||||||
{bot && (
|
{bot && (
|
||||||
|
|
|
@ -3,6 +3,7 @@ import './search.css';
|
||||||
import { useEffect, useRef, useState } from 'preact/hooks';
|
import { useEffect, useRef, useState } from 'preact/hooks';
|
||||||
import { useSearchParams } from 'react-router-dom';
|
import { useSearchParams } from 'react-router-dom';
|
||||||
|
|
||||||
|
import AccountBlock from '../components/account-block';
|
||||||
import Avatar from '../components/avatar';
|
import Avatar from '../components/avatar';
|
||||||
import Icon from '../components/icon';
|
import Icon from '../components/icon';
|
||||||
import Link from '../components/link';
|
import Link from '../components/link';
|
||||||
|
@ -87,13 +88,7 @@ function Search() {
|
||||||
<ul class="timeline flat accounts-list">
|
<ul class="timeline flat accounts-list">
|
||||||
{accountResults.map((account) => (
|
{accountResults.map((account) => (
|
||||||
<li>
|
<li>
|
||||||
<Avatar url={account.avatar} size="xl" />
|
<AccountBlock account={account} instance={instance} />
|
||||||
<NameText
|
|
||||||
account={account}
|
|
||||||
instance={instance}
|
|
||||||
showAcct
|
|
||||||
/>
|
|
||||||
<br />
|
|
||||||
</li>
|
</li>
|
||||||
))}
|
))}
|
||||||
</ul>
|
</ul>
|
||||||
|
|
Loading…
Add table
Reference in a new issue