From ddb1cd9769882c854c28428f59567b299b63bc07 Mon Sep 17 00:00:00 2001 From: DIYgod Date: Tue, 9 Jul 2024 23:22:54 +0800 Subject: [PATCH] feat: profiles page --- src/renderer/src/components/feed-icon.tsx | 1 + src/renderer/src/hono.ts | 9 +- .../(with-layout)/feed/[id]/index.tsx | 3 +- .../(with-layout)/profile/[id]/index.tsx | 115 ++++++++++++++++++ .../(with-layout)/profile/[id]}/layout.tsx | 0 .../(layer)/(subview)/profile/index.tsx | 62 ---------- 6 files changed, 122 insertions(+), 68 deletions(-) create mode 100644 src/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx rename src/renderer/src/pages/{(main)/(layer)/(subview)/profile => (external)/(with-layout)/profile/[id]}/layout.tsx (100%) delete mode 100644 src/renderer/src/pages/(main)/(layer)/(subview)/profile/index.tsx diff --git a/src/renderer/src/components/feed-icon.tsx b/src/renderer/src/components/feed-icon.tsx index 3b3975203..3712dba42 100644 --- a/src/renderer/src/components/feed-icon.tsx +++ b/src/renderer/src/components/feed-icon.tsx @@ -21,6 +21,7 @@ export function FeedIcon({ return ( @@ -98,8 +99,6 @@ export function Component() { - follow on - {" "} {APP_NAME} diff --git a/src/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx b/src/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx new file mode 100644 index 000000000..29bfc2207 --- /dev/null +++ b/src/renderer/src/pages/(external)/(with-layout)/profile/[id]/index.tsx @@ -0,0 +1,115 @@ +import { FeedIcon } from "@renderer/components/feed-icon" +import { FollowIcon } from "@renderer/components/icons/follow" +import { + Avatar, + AvatarFallback, + AvatarImage, +} from "@renderer/components/ui/avatar" +import { StyledButton } from "@renderer/components/ui/button" +import { useAuthQuery } from "@renderer/hooks/common" +import { apiClient } from "@renderer/lib/api-fetch" +import { APP_NAME } from "@renderer/lib/constants" +import { defineQuery } from "@renderer/lib/defineQuery" +import { capitalizeFirstLetter } from "@renderer/lib/utils" +import { DEEPLINK_SCHEME } from "@shared/constants" +import { Helmet } from "react-helmet-async" +import { useParams } from "react-router-dom" +import { parse } from "tldts" + +export function Component() { + const { id } = useParams() + + const user = useAuthQuery(defineQuery(["profiles", id], async () => { + const res = await apiClient.profiles.$get({ + query: { id: id! }, + }) + return res.data + }), { + enabled: !!id, + }) + + const subscriptions = useAuthQuery(defineQuery(["subscriptions", user.data?.id], async () => { + const res = await apiClient.subscriptions.$get({ + query: { userId: user.data?.id }, + }) + const groupFolder = {} as Record + + for (const subscription of (res.data || [])) { + if (!subscription.category && subscription.feeds) { + const { siteUrl } = subscription.feeds + if (!siteUrl) continue + const parsed = parse(siteUrl) + parsed.domain && + (subscription.category = capitalizeFirstLetter(parsed.domain)) + } + if (subscription.category) { + if (!groupFolder[subscription.category]) { + groupFolder[subscription.category] = [] + } + groupFolder[subscription.category].push(subscription) + } + } + + return groupFolder + }), { + enabled: !!user.data?.id, + }) + + return ( + <> + {user.data && ( +
+ + + {user.data.name} + {" "} + | + {" "} + {APP_NAME} + + + + + {user.data.name?.slice(0, 2)} + +
+
+

{user.data.name}

+
+
+ {user.data.handle} +
+
+
+ {Object.keys(subscriptions.data || {}).map((category) => ( +
+
+

{category}

+
+
+ {subscriptions.data?.[category].map((subscription) => ( + + ))} +
+
+ ))} +
+
+ )} + + ) +} diff --git a/src/renderer/src/pages/(main)/(layer)/(subview)/profile/layout.tsx b/src/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx similarity index 100% rename from src/renderer/src/pages/(main)/(layer)/(subview)/profile/layout.tsx rename to src/renderer/src/pages/(external)/(with-layout)/profile/[id]/layout.tsx diff --git a/src/renderer/src/pages/(main)/(layer)/(subview)/profile/index.tsx b/src/renderer/src/pages/(main)/(layer)/(subview)/profile/index.tsx deleted file mode 100644 index 9b3df458f..000000000 --- a/src/renderer/src/pages/(main)/(layer)/(subview)/profile/index.tsx +++ /dev/null @@ -1,62 +0,0 @@ -import { useUser } from "@renderer/atoms/user" -import { - Avatar, - AvatarFallback, - AvatarImage, -} from "@renderer/components/ui/avatar" -import { StyledButton } from "@renderer/components/ui/button" -import { useSignOut } from "@renderer/hooks/biz/useSignOut" -import { views } from "@renderer/lib/constants" -import { cn } from "@renderer/lib/utils" -import { FeedList } from "@renderer/modules/feed-column/list" - -export function Component() { - const user = useUser() - const signOut = useSignOut() - return ( -
-
- - - {user?.name?.slice(0, 2)} - -
{user?.name}
- -
- { - signOut() - }} - > - Sign out - -
-
- -
-
-
Subscriptions
-
- {views.map((view, index) => ( -
-
- - {view.icon} - - {view.name} -
- -
- ))} -
-
-
-
- ) -}