From a612db65c721fe3da26318e4716661fc0bb89369 Mon Sep 17 00:00:00 2001 From: Martti Malmi Date: Sun, 26 Nov 2023 12:07:41 +0200 Subject: [PATCH] add follow distance indicator to profile pages --- .../Element/User/FollowDistanceIndicator.tsx | 28 ++++++++++ .../app/src/Element/User/ProfileImage.tsx | 16 ++---- .../app/src/Pages/Profile/ProfilePage.tsx | 52 ++++++++++--------- 3 files changed, 59 insertions(+), 37 deletions(-) create mode 100644 packages/app/src/Element/User/FollowDistanceIndicator.tsx diff --git a/packages/app/src/Element/User/FollowDistanceIndicator.tsx b/packages/app/src/Element/User/FollowDistanceIndicator.tsx new file mode 100644 index 00000000..4e6197b3 --- /dev/null +++ b/packages/app/src/Element/User/FollowDistanceIndicator.tsx @@ -0,0 +1,28 @@ +import React from "react"; +import { HexKey, socialGraphInstance } from "@snort/system"; +import Icon from "@/Icons/Icon"; +import classNames from "classnames"; + +interface FollowDistanceIndicatorProps { + pubkey: HexKey; + className?: string; +} + +export default function FollowDistanceIndicator({ pubkey, className }: FollowDistanceIndicatorProps) { + const followDistance = socialGraphInstance.getFollowDistance(pubkey); + let followDistanceColor = ""; + + if (followDistance <= 1) { + followDistanceColor = "success"; + } else if (followDistance === 2 && socialGraphInstance.followedByFriendsCount(pubkey) >= 10) { + followDistanceColor = "text-nostr-orange"; + } else if (followDistance > 2) { + return null; + } + + return ( + + + + ); +} diff --git a/packages/app/src/Element/User/ProfileImage.tsx b/packages/app/src/Element/User/ProfileImage.tsx index 629de337..2a6152d2 100644 --- a/packages/app/src/Element/User/ProfileImage.tsx +++ b/packages/app/src/Element/User/ProfileImage.tsx @@ -11,6 +11,7 @@ import Icon from "@/Icons/Icon"; import DisplayName from "./DisplayName"; import { ProfileLink } from "./ProfileLink"; import { ProfileCard } from "./ProfileCard"; +import FollowDistanceIndicator from "@/Element/User/FollowDistanceIndicator"; export interface ProfileImageProps { pubkey: HexKey; @@ -49,7 +50,6 @@ export default function ProfileImage({ }: ProfileImageProps) { const user = useUserProfile(profile ? "" : pubkey) ?? profile; const nip05 = defaultNip ? defaultNip : user?.nip05; - const followDistance = socialGraphInstance.getFollowDistance(pubkey); const [isHovering, setIsHovering] = useState(false); const hoverTimeoutRef = useRef(null); @@ -72,12 +72,6 @@ export default function ProfileImage({ } function inner() { - let followDistanceColor = ""; - if (followDistance <= 1) { - followDistanceColor = "success"; - } else if (followDistance === 2 && socialGraphInstance.followedByFriendsCount(pubkey) >= 10) { - followDistanceColor = "text-nostr-orange"; - } return ( <>
@@ -87,14 +81,10 @@ export default function ProfileImage({ size={size} imageOverlay={imageOverlay} icons={ - (followDistance <= 2 && showFollowDistance) || icons ? ( + showFollowDistance || icons ? ( <> {icons} - {showFollowDistance && ( -
- -
- )} + {showFollowDistance && } ) : undefined } diff --git a/packages/app/src/Pages/Profile/ProfilePage.tsx b/packages/app/src/Pages/Profile/ProfilePage.tsx index 558cfa0b..3e60f43d 100644 --- a/packages/app/src/Pages/Profile/ProfilePage.tsx +++ b/packages/app/src/Pages/Profile/ProfilePage.tsx @@ -60,6 +60,7 @@ import { UserWebsiteLink } from "@/Element/User/UserWebsiteLink"; import { useMuteList, usePinList } from "@/Hooks/useLists"; import messages from "../messages"; +import FollowDistanceIndicator from "@/Element/User/FollowDistanceIndicator"; interface ProfilePageProps { id?: string; @@ -163,31 +164,34 @@ export default function ProfilePage({ id: propId, state }: ProfilePageProps) { {user?.nip05 && } - {followedByFriends.size > 0 && ( -
- - - - {Array.from(followedByFriends) - .slice(0, MAX_FOLLOWED_BY_FRIENDS) - .map(a => { - return ( - - - - ); - })} - {followedByFriends.size > MAX_FOLLOWED_BY_FRIENDS && ( - - +
+ {user?.pubkey && } + {followedByFriends.size > 0 && ( +
+ + - )} -
- )} + {Array.from(followedByFriends) + .slice(0, MAX_FOLLOWED_BY_FRIENDS) + .map(a => { + return ( + + + + ); + })} + {followedByFriends.size > MAX_FOLLOWED_BY_FRIENDS && ( + + + + )} +
+ )} +
{showBadges && } {showStatus && <>{musicStatus()}}