2022-12-27 23:46:13 +00:00
|
|
|
|
import "./ProfilePage.css";
|
2023-01-09 11:00:23 +00:00
|
|
|
|
|
2023-01-10 10:30:33 +00:00
|
|
|
|
import { useEffect, useMemo, useState } from "react";
|
2023-01-09 11:00:23 +00:00
|
|
|
|
import { useSelector } from "react-redux";
|
2022-12-29 22:23:41 +00:00
|
|
|
|
import { FontAwesomeIcon } from "@fortawesome/react-fontawesome";
|
2023-01-16 17:48:25 +00:00
|
|
|
|
import { faGear, faEnvelope } from "@fortawesome/free-solid-svg-icons";
|
2023-01-09 11:00:23 +00:00
|
|
|
|
import { useNavigate, useParams } from "react-router-dom";
|
2022-12-29 22:23:41 +00:00
|
|
|
|
|
|
|
|
|
import useProfile from "../feed/ProfileFeed";
|
2023-01-01 20:31:09 +00:00
|
|
|
|
import FollowButton from "../element/FollowButton";
|
2023-01-14 12:25:08 +00:00
|
|
|
|
import { extractLnAddress, parseId, hexToBech32 } from "../Util";
|
2023-01-16 17:31:17 +00:00
|
|
|
|
import Avatar from "../element/Avatar";
|
2023-01-04 13:23:05 +00:00
|
|
|
|
import Timeline from "../element/Timeline";
|
2023-01-14 14:37:31 +00:00
|
|
|
|
import Text from '../element/Text'
|
2023-01-07 20:54:12 +00:00
|
|
|
|
import LNURLTip from "../element/LNURLTip";
|
2023-01-15 12:02:45 +00:00
|
|
|
|
import Nip05 from "../element/Nip05";
|
2023-01-09 11:00:23 +00:00
|
|
|
|
import Copy from "../element/Copy";
|
2023-01-10 10:30:33 +00:00
|
|
|
|
import ProfilePreview from "../element/ProfilePreview";
|
|
|
|
|
import FollowersList from "../element/FollowersList";
|
2023-01-10 12:05:36 +00:00
|
|
|
|
import FollowsList from "../element/FollowsList";
|
2023-01-16 17:48:25 +00:00
|
|
|
|
import { RootState } from "../state/Store";
|
|
|
|
|
import { HexKey } from "../nostr";
|
2023-01-10 10:30:33 +00:00
|
|
|
|
|
2023-01-16 17:48:25 +00:00
|
|
|
|
enum ProfileTab {
|
|
|
|
|
Notes = "Notes",
|
|
|
|
|
Reactions = "Reactions",
|
|
|
|
|
Followers = "Followers",
|
|
|
|
|
Follows = "Follows"
|
2023-01-10 10:30:33 +00:00
|
|
|
|
};
|
2022-12-18 14:51:32 +00:00
|
|
|
|
|
|
|
|
|
export default function ProfilePage() {
|
|
|
|
|
const params = useParams();
|
2023-01-09 11:00:23 +00:00
|
|
|
|
const navigate = useNavigate();
|
2023-01-16 17:48:25 +00:00
|
|
|
|
const id = useMemo(() => parseId(params.id!), [params]);
|
|
|
|
|
const user = useProfile(id)?.get(id);
|
|
|
|
|
const loginPubKey = useSelector<RootState, HexKey | undefined>(s => s.login.publicKey);
|
|
|
|
|
const follows = useSelector<RootState, HexKey[]>(s => s.login.follows);
|
2022-12-27 23:46:13 +00:00
|
|
|
|
const isMe = loginPubKey === id;
|
2023-01-16 17:48:25 +00:00
|
|
|
|
const [showLnQr, setShowLnQr] = useState<boolean>(false);
|
2023-01-10 10:30:33 +00:00
|
|
|
|
const [tab, setTab] = useState(ProfileTab.Notes);
|
2023-01-16 17:39:30 +00:00
|
|
|
|
const about = Text({ content: user?.about || '', tags: [], users: new Map() })
|
2023-01-10 10:30:33 +00:00
|
|
|
|
|
|
|
|
|
useEffect(() => {
|
|
|
|
|
setTab(ProfileTab.Notes);
|
|
|
|
|
}, [params]);
|
2022-12-28 14:51:33 +00:00
|
|
|
|
|
2023-01-13 22:48:24 +00:00
|
|
|
|
function username() {
|
2023-01-16 17:48:25 +00:00
|
|
|
|
return (
|
|
|
|
|
<div className="name">
|
|
|
|
|
<h2>{user?.display_name || user?.name || 'Nostrich'}</h2>
|
|
|
|
|
<Copy text={params.id || ""} />
|
|
|
|
|
{user?.nip05 && <Nip05 nip05={user.nip05} pubkey={user.pubkey} />}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2023-01-13 22:48:24 +00:00
|
|
|
|
}
|
|
|
|
|
|
2023-01-14 13:28:22 +00:00
|
|
|
|
function bio() {
|
2023-01-09 11:00:23 +00:00
|
|
|
|
const lnurl = extractLnAddress(user?.lud16 || user?.lud06 || "");
|
2022-12-28 23:28:28 +00:00
|
|
|
|
return (
|
2023-01-13 22:48:24 +00:00
|
|
|
|
<div className="details">
|
2023-01-15 10:41:34 +00:00
|
|
|
|
<div>{about}</div>
|
2023-01-10 07:09:09 +00:00
|
|
|
|
|
2023-01-15 22:59:28 +00:00
|
|
|
|
<div className="links">
|
2023-01-16 17:48:25 +00:00
|
|
|
|
{user?.website && (
|
|
|
|
|
<div className="website f-ellipsis">
|
|
|
|
|
<a href={user.website} target="_blank" rel="noreferrer">{user.website}</a>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2023-01-01 20:31:09 +00:00
|
|
|
|
|
2023-01-16 17:48:25 +00:00
|
|
|
|
{lnurl && (
|
|
|
|
|
<div className="f-ellipsis" onClick={(e) => setShowLnQr(true)}>
|
|
|
|
|
<span className="zap">⚡️</span>
|
|
|
|
|
<span className="lnurl" >
|
|
|
|
|
{lnurl}
|
|
|
|
|
</span>
|
|
|
|
|
</div>
|
|
|
|
|
)}
|
2023-01-15 22:59:28 +00:00
|
|
|
|
</div>
|
2023-01-09 11:00:23 +00:00
|
|
|
|
<LNURLTip svc={lnurl} show={showLnQr} onClose={() => setShowLnQr(false)} />
|
2023-01-13 22:48:24 +00:00
|
|
|
|
</div>
|
2022-12-28 23:28:28 +00:00
|
|
|
|
)
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-10 10:30:33 +00:00
|
|
|
|
function tabContent() {
|
|
|
|
|
switch (tab) {
|
2023-01-17 00:54:08 +00:00
|
|
|
|
case ProfileTab.Notes:
|
2023-01-17 21:55:53 +00:00
|
|
|
|
return <Timeline key={id} pubkeys={[id]} global={false} postsOnly={false} method={"LIMIT_UNTIL"} />;
|
2023-01-10 10:30:33 +00:00
|
|
|
|
case ProfileTab.Follows: {
|
|
|
|
|
if (isMe) {
|
2023-01-10 14:36:23 +00:00
|
|
|
|
return (
|
|
|
|
|
<>
|
|
|
|
|
<h4>Following {follows.length}</h4>
|
|
|
|
|
{follows.map(a => <ProfilePreview key={a} pubkey={a.toLowerCase()} options={{ about: false }} />)}
|
|
|
|
|
</>
|
|
|
|
|
);
|
2023-01-10 12:05:36 +00:00
|
|
|
|
} else {
|
|
|
|
|
return <FollowsList pubkey={id} />;
|
2023-01-10 10:30:33 +00:00
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
case ProfileTab.Followers: {
|
|
|
|
|
return <FollowersList pubkey={id} />
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2023-01-14 13:28:22 +00:00
|
|
|
|
function avatar() {
|
2023-01-15 19:40:47 +00:00
|
|
|
|
return (
|
|
|
|
|
<div className="avatar-wrapper">
|
2023-01-16 17:31:17 +00:00
|
|
|
|
<Avatar user={user} />
|
2023-01-15 19:40:47 +00:00
|
|
|
|
</div>
|
|
|
|
|
)
|
2023-01-14 13:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function userDetails() {
|
2023-01-15 19:40:47 +00:00
|
|
|
|
return (
|
|
|
|
|
<div className="details-wrapper">
|
|
|
|
|
{username()}
|
|
|
|
|
{isMe ? (
|
|
|
|
|
<div className="btn btn-icon follow-button" onClick={() => navigate("/settings")}>
|
|
|
|
|
<FontAwesomeIcon icon={faGear} size="lg" />
|
|
|
|
|
</div>
|
|
|
|
|
) : <>
|
|
|
|
|
<div className="btn message-button" onClick={() => navigate(`/messages/${hexToBech32("npub", id)}`)}>
|
|
|
|
|
<FontAwesomeIcon icon={faEnvelope} size="lg" />
|
|
|
|
|
</div>
|
|
|
|
|
<FollowButton pubkey={id} />
|
|
|
|
|
</>
|
|
|
|
|
}
|
|
|
|
|
{bio()}
|
|
|
|
|
</div>
|
|
|
|
|
)
|
2023-01-14 13:28:22 +00:00
|
|
|
|
}
|
|
|
|
|
|
2022-12-18 14:51:32 +00:00
|
|
|
|
return (
|
2022-12-28 23:28:28 +00:00
|
|
|
|
<>
|
2023-01-03 16:55:51 +00:00
|
|
|
|
<div className="profile flex">
|
2023-01-15 19:40:47 +00:00
|
|
|
|
{user?.banner && <img alt="banner" className="banner" src={user.banner} />}
|
2023-01-14 13:28:22 +00:00
|
|
|
|
{user?.banner ? (
|
2023-01-15 19:40:47 +00:00
|
|
|
|
<>
|
|
|
|
|
{avatar()}
|
|
|
|
|
{userDetails()}
|
|
|
|
|
</>
|
2023-01-14 13:28:22 +00:00
|
|
|
|
) : (
|
2023-01-15 19:40:47 +00:00
|
|
|
|
<div className="no-banner">
|
|
|
|
|
{avatar()}
|
|
|
|
|
{userDetails()}
|
|
|
|
|
</div>
|
2023-01-14 13:28:22 +00:00
|
|
|
|
)}
|
2022-12-27 23:46:13 +00:00
|
|
|
|
</div>
|
2022-12-30 14:01:51 +00:00
|
|
|
|
<div className="tabs">
|
2023-01-16 17:48:25 +00:00
|
|
|
|
{[ProfileTab.Notes, ProfileTab.Followers, ProfileTab.Follows].map(v => {
|
|
|
|
|
return <div className={`tab f-1${tab === v ? " active" : ""}`} key={v} onClick={() => setTab(v)}>{v}</div>
|
2023-01-15 19:40:47 +00:00
|
|
|
|
})}
|
2022-12-30 14:01:51 +00:00
|
|
|
|
</div>
|
2023-01-10 10:30:33 +00:00
|
|
|
|
{tabContent()}
|
2022-12-28 23:28:28 +00:00
|
|
|
|
</>
|
2022-12-18 14:51:32 +00:00
|
|
|
|
)
|
2023-01-10 09:18:46 +00:00
|
|
|
|
}
|