From 85169ebe0c32d77584754a8f009bbb35a6bebefc Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Sat, 23 Dec 2023 15:43:06 +0200 Subject: [PATCH] ndk profilepage --- packages/app/src/Element/User/DisplayName.tsx | 9 +++++---- packages/app/src/Hooks/useProfile.ts | 2 +- .../app/src/Pages/Profile/ProfilePage.tsx | 20 +++++++++---------- packages/app/src/SnortUtils/index.ts | 5 +++-- 4 files changed, 19 insertions(+), 17 deletions(-) diff --git a/packages/app/src/Element/User/DisplayName.tsx b/packages/app/src/Element/User/DisplayName.tsx index 1f52c9cb..5523abc0 100644 --- a/packages/app/src/Element/User/DisplayName.tsx +++ b/packages/app/src/Element/User/DisplayName.tsx @@ -1,17 +1,18 @@ import "./DisplayName.css"; import { useMemo } from "react"; -import { HexKey, UserMetadata } from "@snort/system"; +import { HexKey } from "@snort/system"; import { getDisplayNameOrPlaceHolder } from "@/SnortUtils"; -import { useUserProfile } from "@snort/system-react"; import classNames from "classnames"; +import useProfile from "@/Hooks/useProfile"; +import {NDKUserProfile} from "@nostr-dev-kit/ndk"; interface DisplayNameProps { pubkey: HexKey; - user?: UserMetadata | undefined; + user?: NDKUserProfile | undefined; } const DisplayName = ({ pubkey }: DisplayNameProps) => { - const profile = useUserProfile(pubkey); + const profile = useProfile(pubkey); const [name, isPlaceHolder] = useMemo(() => getDisplayNameOrPlaceHolder(profile, pubkey), [profile, pubkey]); return {name}; diff --git a/packages/app/src/Hooks/useProfile.ts b/packages/app/src/Hooks/useProfile.ts index a1ada80e..1e0af74c 100644 --- a/packages/app/src/Hooks/useProfile.ts +++ b/packages/app/src/Hooks/useProfile.ts @@ -2,7 +2,7 @@ import { NDKUserProfile } from "@nostr-dev-kit/ndk"; import { useEffect, useState } from "react"; import ndk from "@/ndk"; -export default function useProfile(pubkey: string) { +export default function useProfile(pubkey: string | undefined) { const [profile, setProfile] = useState(null as NDKUserProfile | null); useEffect(() => { if (pubkey) { diff --git a/packages/app/src/Pages/Profile/ProfilePage.tsx b/packages/app/src/Pages/Profile/ProfilePage.tsx index e1f2eb2e..4463d804 100644 --- a/packages/app/src/Pages/Profile/ProfilePage.tsx +++ b/packages/app/src/Pages/Profile/ProfilePage.tsx @@ -5,14 +5,12 @@ import { Link, useLocation, useNavigate, useParams } from "react-router-dom"; import { encodeTLVEntries, EventKind, - MetadataCache, NostrLink, NostrPrefix, TLVEntryType, tryParseNostrLink, } from "@snort/system"; import { fetchNip05Pubkey, LNURL } from "@snort/shared"; -import { useUserProfile } from "@snort/system-react"; import { findTag, getLinkReactions, hexToBech32, parseId, unwrap } from "@/SnortUtils"; import Note from "@/Element/Event/Note"; @@ -56,20 +54,22 @@ import DisplayName from "@/Element/User/DisplayName"; import { UserWebsiteLink } from "@/Element/User/UserWebsiteLink"; import { useMuteList, usePinList } from "@/Hooks/useLists"; import FollowedBy from "@/Element/User/FollowedBy"; +import useProfile from "@/Hooks/useProfile"; +import {NDKUserProfile} from "@nostr-dev-kit/ndk"; interface ProfilePageProps { id?: string; - state?: MetadataCache; + state?: NDKUserProfile; } export default function ProfilePage({ id: propId, state }: ProfilePageProps) { const params = useParams(); const location = useLocation(); - const profileState = (location.state as MetadataCache | undefined) || state; + const profileState = (location.state as NDKUserProfile | undefined) || state; const navigate = useNavigate(); const [id, setId] = useState(profileState?.pubkey); const [relays, setRelays] = useState>(); - const user = useUserProfile(profileState ? undefined : id) || profileState; + const user = useProfile(id); const login = useLogin(); const loginPubKey = login.publicKey; const isMe = loginPubKey === id; @@ -163,10 +163,10 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) { <>

- - + +

- {user?.nip05 && } + {user?.nip05 && }
{showBadges && } {showStatus && <>{musicStatus()}} @@ -293,7 +293,7 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) { function avatar() { return (
- setModalImage(user?.picture || "")} className="pointer" /> + setModalImage(user?.image || "")} className="pointer" />
{renderIcons()} {!isMe && id && } @@ -363,7 +363,7 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) {
{username()} {bio()} - {user?.pubkey && loginPubKey && } + {id && loginPubKey && }
); } diff --git a/packages/app/src/SnortUtils/index.ts b/packages/app/src/SnortUtils/index.ts index f43f5202..a6e36fed 100644 --- a/packages/app/src/SnortUtils/index.ts +++ b/packages/app/src/SnortUtils/index.ts @@ -21,6 +21,7 @@ import { import { isHex, isOffline } from "@snort/shared"; import { Birthday, Day } from "@/Const"; import AnimalName from "@/Element/User/AnimalName"; +import {NDKUser, NDKUserProfile} from "@nostr-dev-kit/ndk"; export const sha256 = (str: string | Uint8Array): u256 => { return utils.bytesToHex(hash(str)); @@ -498,11 +499,11 @@ export const isBirthday = () => { return CONFIG.appName === "Snort" && IsTheSeason(event, 1); }; -export function getDisplayName(user: UserMetadata | undefined, pubkey: HexKey): string { +export function getDisplayName(user: NDKUserProfile | undefined, pubkey: HexKey): string { return getDisplayNameOrPlaceHolder(user, pubkey)[0]; } -export function getDisplayNameOrPlaceHolder(user: UserMetadata | undefined, pubkey: HexKey): [string, boolean] { +export function getDisplayNameOrPlaceHolder(user: NDKUserProfile | undefined, pubkey: HexKey): [string, boolean] { let name = hexToBech32(NostrPrefix.PublicKey, pubkey).substring(0, 12); let isPlaceHolder = false;