Skip to content

Commit 53a5bae

Browse files
committed
perf: speed up user profile modal data loading
Signed-off-by: Innei <i@innei.in>
1 parent bbc1591 commit 53a5bae

File tree

2 files changed

+34
-13
lines changed

2 files changed

+34
-13
lines changed

src/renderer/src/modules/profile/hooks.ts

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ import { UserProfileModalContent } from "./user-profile-modal"
1111

1212
export const useUserSubscriptionsQuery = (userId: string | undefined) => {
1313
const subscriptions = useAuthQuery(
14-
defineQuery(["subscriptions", userId], async () => {
14+
defineQuery(["subscriptions", "group", userId], async () => {
1515
const res = await apiClient.subscriptions.$get({
1616
query: { userId },
1717
})
@@ -61,7 +61,8 @@ export const usePresentUserProfileModal = (
6161
clickOutsideToDismiss: true,
6262
modal: variant === "dialog",
6363
overlay: variant === "dialog",
64-
modalContainerClassName: variant === "drawer" ? "right-4 left-[auto] top-4 bottom-4" : "",
64+
modalContainerClassName:
65+
variant === "drawer" ? "right-4 left-[auto] top-4 bottom-4" : "",
6566
})
6667
},
6768
[present, variant],

src/renderer/src/modules/profile/user-profile-modal.tsx

Lines changed: 31 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@ import { cn } from "@renderer/lib/utils"
1919
import type { SubscriptionModel } from "@renderer/models"
2020
import { useUserSubscriptionsQuery } from "@renderer/modules/profile/hooks"
2121
import { useSubscriptionStore } from "@renderer/store/subscription"
22+
import { useUserById } from "@renderer/store/user"
2223
import { useAnimationControls } from "framer-motion"
2324
import { throttle } from "lodash-es"
2425
import type { FC } from "react"
@@ -40,6 +41,21 @@ export const UserProfileModalContent: FC<{
4041
return res.data
4142
}),
4243
)
44+
const storeUser = useUserById(userId)
45+
46+
const userInfo = user.data ?
47+
{
48+
avatar: user.data.image,
49+
name: user.data.name,
50+
handle: user.data.handle,
51+
} :
52+
storeUser ?
53+
{
54+
avatar: storeUser.image,
55+
name: storeUser.name,
56+
handle: storeUser.handle,
57+
} :
58+
null
4359

4460
const subscriptions = useUserSubscriptionsQuery(user.data?.id)
4561
const modal = useCurrentModal()
@@ -206,7 +222,7 @@ export const UserProfileModalContent: FC<{
206222
</ActionButton>
207223
</div>
208224

209-
{user.data && (
225+
{userInfo && (
210226
<Fragment>
211227
<div
212228
className={cn(
@@ -222,10 +238,10 @@ export const UserProfileModalContent: FC<{
222238
)}
223239
>
224240
<m.span layout>
225-
<AvatarImage asChild src={user.data.image || undefined}>
241+
<AvatarImage asChild src={userInfo.avatar || undefined}>
226242
<m.img layout />
227243
</AvatarImage>
228-
<AvatarFallback>{user.data.name?.slice(0, 2)}</AvatarFallback>
244+
<AvatarFallback>{userInfo.name?.slice(0, 2)}</AvatarFallback>
229245
</m.span>
230246
</Avatar>
231247
<m.div
@@ -241,14 +257,18 @@ export const UserProfileModalContent: FC<{
241257
isHeaderSimple ? "" : "mt-4",
242258
)}
243259
>
244-
<m.h1 layout>{user.data.name}</m.h1>
260+
<m.h1 layout>{userInfo.name}</m.h1>
261+
</m.div>
262+
263+
<m.div
264+
className={cn(
265+
"mb-0 text-sm text-zinc-500",
266+
userInfo.handle ? "visible" : "invisible select-none",
267+
)}
268+
layout
269+
>
270+
@{userInfo.handle}
245271
</m.div>
246-
{!!user.data.handle && (
247-
<m.div className="mb-0 text-sm text-zinc-500" layout>
248-
@
249-
{user.data.handle}
250-
</m.div>
251-
)}
252272
</m.div>
253273
</div>
254274
<ScrollArea.ScrollArea
@@ -284,7 +304,7 @@ export const UserProfileModalContent: FC<{
284304
</Fragment>
285305
)}
286306

287-
{!user.data && <LoadingCircle size="large" className="center h-full" />}
307+
{!userInfo && <LoadingCircle size="large" className="center h-full" />}
288308
</m.div>
289309
</div>
290310
)

0 commit comments

Comments
 (0)