From 8608765e7976009e13ba2a1275990e35b0012d38 Mon Sep 17 00:00:00 2001 From: daniyal Date: Wed, 25 Sep 2024 20:55:48 +0500 Subject: [PATCH] fix: display profile box even if user does not have metadata --- src/components/ProfileSection.tsx | 87 +++++++++++++++++++------------ src/constants.ts | 6 ++- src/pages/search.tsx | 13 ++++- 3 files changed, 71 insertions(+), 35 deletions(-) diff --git a/src/components/ProfileSection.tsx b/src/components/ProfileSection.tsx index 58a82c5..fa4d6e8 100644 --- a/src/components/ProfileSection.tsx +++ b/src/components/ProfileSection.tsx @@ -1,3 +1,4 @@ +import { FALLBACK_PROFILE_IMAGE } from 'constants.ts' import { Event, Filter, kinds, nip19, UnsignedEvent } from 'nostr-tools' import { QRCodeSVG } from 'qrcode.react' import { useState } from 'react' @@ -9,16 +10,21 @@ import { UserRelaysType } from '../controllers' import { useAppSelector, useDidMount } from '../hooks' -import { getProfilePageRoute } from '../routes' +import { appRoutes, getProfilePageRoute } from '../routes' import '../styles/author.css' import '../styles/innerPage.css' import '../styles/socialPosts.css' import { UserProfile } from '../types' -import { copyTextToClipboard, log, LogType, now, npubToHex } from '../utils' +import { + copyTextToClipboard, + hexToNpub, + log, + LogType, + now, + npubToHex +} from '../utils' import { LoadingSpinner } from './LoadingSpinner' import { ZapPopUp } from './Zap' -import { NDKUserProfile } from '@nostr-dev-kit/ndk' -import _ from 'lodash' type Props = { pubkey: string @@ -34,13 +40,22 @@ export const ProfileSection = ({ pubkey }: Props) => { }) }) - if (!profile) return null + const displayName = + profile?.displayName || profile?.name || '[name not set up]' + const about = profile?.bio || profile?.about || '[bio not set up]' return (
- +
@@ -91,12 +106,26 @@ export const ProfileSection = ({ pubkey }: Props) => { } type ProfileProps = { - profile: NDKUserProfile + pubkey: string + displayName: string + about: string + image?: string + nip05?: string + lud16?: string } -export const Profile = ({ profile }: ProfileProps) => { +export const Profile = ({ + pubkey, + displayName, + about, + image, + nip05, + lud16 +}: ProfileProps) => { + const npub = hexToNpub(pubkey) + const handleCopy = async () => { - copyTextToClipboard(profile.npub as string).then((isCopied) => { + copyTextToClipboard(npub).then((isCopied) => { if (isCopied) { toast.success('Npub copied to clipboard!') } else { @@ -107,25 +136,15 @@ export const Profile = ({ profile }: ProfileProps) => { }) } - const hexPubkey = npubToHex(profile.pubkey as string) - - if (!hexPubkey) return null - - const profileRoute = getProfilePageRoute( - nip19.nprofileEncode({ - pubkey: hexPubkey - }) - ) - - const npub = (profile.npub as string) || '' - const displayName = - profile.displayName || - profile.name || - _.truncate(npub, { - length: 16 - }) - const nip05 = profile.nip05 || '' - const about = profile.bio || profile.about || '' + let profileRoute = appRoutes.home + const hexPubkey = npubToHex(pubkey) + if (hexPubkey) { + profileRoute = getProfilePageRoute( + nip19.nprofileEncode({ + pubkey: hexPubkey + }) + ) + } return (
@@ -142,7 +161,7 @@ export const Profile = ({ profile }: ProfileProps) => { className='IBMSMSMSSS_Author_Top_PP' style={{ background: `url('${ - profile.image || '' + image || FALLBACK_PROFILE_IMAGE }') center / cover no-repeat` }} >
@@ -151,7 +170,9 @@ export const Profile = ({ profile }: ProfileProps) => {

{displayName}

-

{nip05}

+ {nip05 && ( +

{nip05}

+ )}
@@ -182,8 +203,8 @@ export const Profile = ({ profile }: ProfileProps) => {
- - + + {lud16 && }
@@ -196,7 +217,7 @@ export const Profile = ({ profile }: ProfileProps) => { > - + ) } diff --git a/src/constants.ts b/src/constants.ts index f4d141b..207bc80 100644 --- a/src/constants.ts +++ b/src/constants.ts @@ -15,7 +15,7 @@ export const LANDING_PAGE_DATA = { ], featuredGames: [ 'Persona 3 Reload', - 'Baldur\'s Gate 3', + "Baldur's Gate 3", 'Cyberpunk 2077', 'ELDEN RING', 'FINAL FANTASY VII REMAKE INTERGRADE' @@ -119,3 +119,7 @@ export const GAME_FILES = [ export const MAX_MODS_PER_PAGE = 10 export const MAX_GAMES_PER_PAGE = 10 + +// todo: add game and mod fallback image here +export const FALLBACK_PROFILE_IMAGE = + 'https://image.nostr.build/a305f4b43f74af3c6dcda42e6a798105a56ac1e3e7b74d7bef171896b3ba7520.png' diff --git a/src/pages/search.tsx b/src/pages/search.tsx index f507dd9..3c01ef0 100644 --- a/src/pages/search.tsx +++ b/src/pages/search.tsx @@ -552,9 +552,20 @@ const UsersResult = ({
{filteredProfiles.map((profile) => { if (profile.pubkey) { + const displayName = + profile?.displayName || profile?.name || '[name not set up]' + const about = profile?.bio || profile?.about || '[bio not set up]' + return ( - + ) }