From 53a5bae316b406ff5c250c3e7772ce4071891bee Mon Sep 17 00:00:00 2001 From: Innei Date: Sun, 25 Aug 2024 20:37:45 +0800 Subject: [PATCH] perf: speed up user profile modal data loading Signed-off-by: Innei --- src/renderer/src/modules/profile/hooks.ts | 5 ++- .../modules/profile/user-profile-modal.tsx | 42 ++++++++++++++----- 2 files changed, 34 insertions(+), 13 deletions(-) diff --git a/src/renderer/src/modules/profile/hooks.ts b/src/renderer/src/modules/profile/hooks.ts index 4f3e57b5f3..171a0abc3c 100644 --- a/src/renderer/src/modules/profile/hooks.ts +++ b/src/renderer/src/modules/profile/hooks.ts @@ -11,7 +11,7 @@ import { UserProfileModalContent } from "./user-profile-modal" export const useUserSubscriptionsQuery = (userId: string | undefined) => { const subscriptions = useAuthQuery( - defineQuery(["subscriptions", userId], async () => { + defineQuery(["subscriptions", "group", userId], async () => { const res = await apiClient.subscriptions.$get({ query: { userId }, }) @@ -61,7 +61,8 @@ export const usePresentUserProfileModal = ( clickOutsideToDismiss: true, modal: variant === "dialog", overlay: variant === "dialog", - modalContainerClassName: variant === "drawer" ? "right-4 left-[auto] top-4 bottom-4" : "", + modalContainerClassName: + variant === "drawer" ? "right-4 left-[auto] top-4 bottom-4" : "", }) }, [present, variant], diff --git a/src/renderer/src/modules/profile/user-profile-modal.tsx b/src/renderer/src/modules/profile/user-profile-modal.tsx index 87d8e4415f..a332569302 100644 --- a/src/renderer/src/modules/profile/user-profile-modal.tsx +++ b/src/renderer/src/modules/profile/user-profile-modal.tsx @@ -19,6 +19,7 @@ import { cn } from "@renderer/lib/utils" import type { SubscriptionModel } from "@renderer/models" import { useUserSubscriptionsQuery } from "@renderer/modules/profile/hooks" import { useSubscriptionStore } from "@renderer/store/subscription" +import { useUserById } from "@renderer/store/user" import { useAnimationControls } from "framer-motion" import { throttle } from "lodash-es" import type { FC } from "react" @@ -40,6 +41,21 @@ export const UserProfileModalContent: FC<{ return res.data }), ) + const storeUser = useUserById(userId) + + const userInfo = user.data ? + { + avatar: user.data.image, + name: user.data.name, + handle: user.data.handle, + } : + storeUser ? + { + avatar: storeUser.image, + name: storeUser.name, + handle: storeUser.handle, + } : + null const subscriptions = useUserSubscriptionsQuery(user.data?.id) const modal = useCurrentModal() @@ -206,7 +222,7 @@ export const UserProfileModalContent: FC<{ - {user.data && ( + {userInfo && (
- + - {user.data.name?.slice(0, 2)} + {userInfo.name?.slice(0, 2)} - {user.data.name} + {userInfo.name} + + + + @{userInfo.handle} - {!!user.data.handle && ( - - @ - {user.data.handle} - - )}
)} - {!user.data && } + {!userInfo && } )