snort/src/element/ProfileImage.js

42 lines
1.5 KiB
JavaScript
Raw Normal View History

2023-01-06 14:36:13 +00:00
import "./ProfileImage.css";
import Nostrich from "../nostrich.jpg";
2023-01-06 11:04:25 +00:00
2023-01-06 14:36:13 +00:00
import { useMemo } from "react";
2023-01-06 11:04:25 +00:00
import { Link, useNavigate } from "react-router-dom";
2022-12-29 22:23:41 +00:00
import useProfile from "../feed/ProfileFeed";
2023-01-10 10:30:33 +00:00
import { hexToBech32, profileLink } from "../Util";
import LazyImage from "./LazyImage";
2023-01-15 12:02:45 +00:00
import Nip05 from "./Nip05";
2022-12-27 23:46:13 +00:00
2023-01-12 09:48:39 +00:00
export default function ProfileImage({ pubkey, subHeader, showUsername = true, className, link }) {
2022-12-27 23:46:13 +00:00
const navigate = useNavigate();
2023-01-02 11:15:13 +00:00
const user = useProfile(pubkey);
2022-12-27 23:46:13 +00:00
2023-01-01 19:57:27 +00:00
const hasImage = (user?.picture?.length ?? 0) > 0;
2023-01-04 11:29:00 +00:00
const name = useMemo(() => {
2023-01-10 10:30:33 +00:00
let name = hexToBech32("npub", pubkey).substring(0, 12);
2023-01-04 11:29:00 +00:00
if (user?.display_name?.length > 0) {
name = user.display_name;
} else if (user?.name?.length > 0) {
name = user.name;
}
return name;
}, [user]);
2023-01-10 10:30:33 +00:00
2022-12-27 23:46:13 +00:00
return (
2023-01-12 09:48:39 +00:00
<div className={`pfp ${className}`}>
<LazyImage src={hasImage ? user.picture : Nostrich} onClick={() => navigate(link ?? profileLink(pubkey))} />
2023-01-12 12:00:44 +00:00
{showUsername && (<div className="f-grow">
2023-01-15 12:46:35 +00:00
<Link key={pubkey} to={link ?? profileLink(pubkey)}>
<div className="profile-name">
<div>{name}</div>
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
2023-01-15 12:46:35 +00:00
</div>
</Link>
2023-01-12 12:00:44 +00:00
{subHeader ? <>{subHeader}</> : null}
2023-01-12 09:48:39 +00:00
</div>
2023-01-10 07:09:09 +00:00
)}
2022-12-27 23:46:13 +00:00
</div>
)
2023-01-15 12:02:45 +00:00
}