feat: lazy load profile preview

This commit is contained in:
Kieran 2023-01-19 15:21:13 +00:00
parent b1f62ea6bc
commit 3b6b1458f2
Signed by: Kieran
GPG Key ID: DE71CEB3925BE941
2 changed files with 11 additions and 6 deletions

View File

@ -2,6 +2,7 @@
display: flex;
padding: 5px 0;
align-items: center;
min-height: 40px;
}
.profile-preview .pfp {

View File

@ -5,6 +5,7 @@ import ProfileImage from "./ProfileImage";
import FollowButton from "./FollowButton";
import useProfile from "../feed/ProfileFeed";
import { HexKey } from "../nostr";
import { useInView } from "react-intersection-observer";
export interface ProfilePreviewProps {
pubkey: HexKey,
@ -16,18 +17,21 @@ export interface ProfilePreviewProps {
export default function ProfilePreview(props: ProfilePreviewProps) {
const pubkey = props.pubkey;
const user = useProfile(pubkey)?.get(pubkey);
const { ref, inView } = useInView({ triggerOnce: true });
const options = {
about: true,
...props.options
};
return (
<div className="profile-preview">
<ProfileImage pubkey={pubkey} subHeader=
{options.about ? <div className="f-ellipsis about">
{user?.about}
</div> : undefined} />
{props.actions ?? <FollowButton pubkey={pubkey} className="ml5" />}
<div className="profile-preview" ref={ref}>
{inView && <>
<ProfileImage pubkey={pubkey} subHeader=
{options.about ? <div className="f-ellipsis about">
{user?.about}
</div> : undefined} />
{props.actions ?? <FollowButton pubkey={pubkey} className="ml5" />}
</>}
</div>
)
}