From 130a6d62dcf3a253496ec264d035d2be706c871e Mon Sep 17 00:00:00 2001 From: Shaurya Gupta Date: Sat, 14 Dec 2024 21:33:42 +0530 Subject: [PATCH] refactor: Improve UserAvatar component --- src/components/Users/UserAvatar.tsx | 22 ++++++++++------------ 1 file changed, 10 insertions(+), 12 deletions(-) diff --git a/src/components/Users/UserAvatar.tsx b/src/components/Users/UserAvatar.tsx index 2f22c8fc25a..aa7c12e7423 100644 --- a/src/components/Users/UserAvatar.tsx +++ b/src/components/Users/UserAvatar.tsx @@ -21,7 +21,7 @@ import { formatDisplayName, sleep } from "@/Utils/utils"; export default function UserAvatar({ username, - refetchUserData: userDataRefetch, + refetchUserData, }: { username: string; refetchUserData?: () => void; @@ -30,15 +30,14 @@ export default function UserAvatar({ const [editAvatar, setEditAvatar] = useState(false); const authUser = useAuthUser(); - const { - data: userData, - loading: isLoading, - refetch: refetchUserData, - } = useTanStackQueryInstead(routes.getUserDetails, { - pathParams: { - username: username, + const { data: userData, loading: isLoading } = useTanStackQueryInstead( + routes.getUserDetails, + { + pathParams: { + username: username, + }, }, - }); + ); if (isLoading || !userData) { return ; @@ -60,7 +59,7 @@ export default function UserAvatar({ async (xhr: XMLHttpRequest) => { if (xhr.status === 200) { await sleep(1000); - userDataRefetch?.(); + refetchUserData?.(); Notification.Success({ msg: t("avatar_updated_success") }); setEditAvatar(false); } @@ -78,8 +77,7 @@ export default function UserAvatar({ }); if (res?.ok) { Notification.Success({ msg: "Profile picture deleted" }); - await refetchUserData(); - await userDataRefetch?.(); + refetchUserData?.(); setEditAvatar(false); } else { onError();