From f944693a2af49cb285538b23a3634204dbeaf345 Mon Sep 17 00:00:00 2001
From: Ren Amamiya <123083837+reyamir@users.noreply.github.com>
Date: Mon, 19 Jun 2023 11:32:52 +0700
Subject: [PATCH] add profile block to space
---
src/app/space/components/blocks/profile.tsx | 107 ++++++++++++++++++++
src/app/user/_default.page.tsx | 1 -
src/app/user/layout.tsx | 14 ---
src/app/user/pages/index.page.tsx | 13 ---
src/shared/user.tsx | 22 ++--
5 files changed, 118 insertions(+), 39 deletions(-)
create mode 100644 src/app/space/components/blocks/profile.tsx
delete mode 100644 src/app/user/_default.page.tsx
delete mode 100644 src/app/user/layout.tsx
delete mode 100644 src/app/user/pages/index.page.tsx
diff --git a/src/app/space/components/blocks/profile.tsx b/src/app/space/components/blocks/profile.tsx
new file mode 100644
index 00000000..4ec091ad
--- /dev/null
+++ b/src/app/space/components/blocks/profile.tsx
@@ -0,0 +1,107 @@
+import { ArrowLeftIcon } from "@shared/icons";
+import { Image } from "@shared/image";
+import { useActiveAccount } from "@stores/accounts";
+import { DEFAULT_AVATAR } from "@stores/constants";
+import { useProfile } from "@utils/hooks/useProfile";
+import { compactNumber } from "@utils/number";
+import { shortenKey } from "@utils/shortenKey";
+import useSWR from "swr";
+
+const fetcher = (url: string) => fetch(url).then((r) => r.json());
+
+export function ProfileBlock({ params }: { params: any }) {
+ const removeBlock = useActiveAccount((state: any) => state.removeBlock);
+
+ const close = () => {
+ removeBlock(params.id, true);
+ };
+
+ const { user } = useProfile(params.pubkey);
+ const { data: userStats } = useSWR(
+ user ? `https://api.nostr.band/v0/stats/profile/${params.pubkey}` : null,
+ fetcher,
+ );
+
+ return (
+
+
+
+
{params.title}
+
+
+
+
+
+
+
+
+
+
+
+ {user?.display_name || user?.name || "Anon"}
+
+
+ {user?.nip05 || shortenKey(params.pubkey)}
+
+
+ {user?.bio || user.about}
+
+
+ {!userStats ? (
+
Loading...
+ ) : (
+
+
+
+ {userStats.stats[params.pubkey]
+ .followers_pubkey_count ?? 0}
+
+
+ Followers
+
+
+
+
+ {userStats.stats[params.pubkey]
+ .pub_following_pubkey_count ?? 0}
+
+
+ Following
+
+
+
+
+ {userStats.stats[params.pubkey].zaps_received
+ ? compactNumber.format(
+ userStats.stats[params.pubkey].zaps_received
+ .msats / 1000,
+ )
+ : 0}
+
+
+ Zaps received
+
+
+
+ )}
+
+
+
+
+
+
+ );
+}
diff --git a/src/app/user/_default.page.tsx b/src/app/user/_default.page.tsx
deleted file mode 100644
index e4596971..00000000
--- a/src/app/user/_default.page.tsx
+++ /dev/null
@@ -1 +0,0 @@
-export { LayoutUser as Layout } from "./layout";
diff --git a/src/app/user/layout.tsx b/src/app/user/layout.tsx
deleted file mode 100644
index 90a31e26..00000000
--- a/src/app/user/layout.tsx
+++ /dev/null
@@ -1,14 +0,0 @@
-import { MultiAccounts } from "@shared/multiAccounts";
-import { Navigation } from "@shared/navigation";
-
-export function LayoutUser({ children }: { children: React.ReactNode }) {
- return (
-
- );
-}
diff --git a/src/app/user/pages/index.page.tsx b/src/app/user/pages/index.page.tsx
deleted file mode 100644
index aec93a38..00000000
--- a/src/app/user/pages/index.page.tsx
+++ /dev/null
@@ -1,13 +0,0 @@
-import { usePageContext } from "@utils/hooks/usePageContext";
-
-export function Page() {
- const pageContext = usePageContext();
- const searchParams: any = pageContext.urlParsed.search;
- const pubkey = searchParams.pubkey;
-
- return (
-
- );
-}
diff --git a/src/shared/user.tsx b/src/shared/user.tsx
index 297cd5ae..9b6c45d1 100644
--- a/src/shared/user.tsx
+++ b/src/shared/user.tsx
@@ -65,27 +65,27 @@ export function User({
leaveFrom="opacity-100 translate-y-0"
leaveTo="opacity-0 translate-y-1"
>
-
-
-
+
+
+
-
-
-
+
+
+
{user?.displayName || user?.name || (
)}
-
+
{user?.nip05 || shortenKey(pubkey)}
@@ -94,13 +94,13 @@ export function User({