snort/packages/app/src/Element/ProfilePreview.tsx

47 lines
1.3 KiB
TypeScript
Raw Normal View History

2023-01-01 19:57:27 +00:00
import "./ProfilePreview.css";
2023-01-19 00:03:24 +00:00
import { ReactNode } from "react";
2023-01-20 11:11:50 +00:00
import ProfileImage from "Element/ProfileImage";
import FollowButton from "Element/FollowButton";
2023-03-03 14:30:31 +00:00
import { useUserProfile } from "Hooks/useUserProfile";
2023-02-11 20:05:46 +00:00
import { HexKey } from "@snort/nostr";
2023-01-19 15:21:13 +00:00
import { useInView } from "react-intersection-observer";
2023-01-01 19:57:27 +00:00
2023-01-16 17:48:25 +00:00
export interface ProfilePreviewProps {
pubkey: HexKey;
options?: {
about?: boolean;
};
actions?: ReactNode;
className?: string;
2023-01-16 17:48:25 +00:00
}
export default function ProfilePreview(props: ProfilePreviewProps) {
const pubkey = props.pubkey;
const { ref, inView } = useInView({ triggerOnce: true });
2023-05-10 13:24:22 +00:00
const user = useUserProfile(inView ? pubkey : undefined);
const options = {
about: true,
...props.options,
};
2023-01-01 19:57:27 +00:00
return (
2023-02-12 12:31:48 +00:00
<>
<div className={`profile-preview${props.className ? ` ${props.className}` : ""}`} ref={ref}>
{inView && (
<>
<ProfileImage
pubkey={pubkey}
subHeader={options.about ? <div className="about">{user?.about}</div> : undefined}
/>
{props.actions ?? (
<div className="follow-button-container">
<FollowButton pubkey={pubkey} />
</div>
)}
</>
)}
</div>
</>
);
}