Skip to content

Commit

Permalink
refactor: Improve UserAvatar component
Browse files Browse the repository at this point in the history
  • Loading branch information
shauryag2002 committed Dec 14, 2024
1 parent 2c4b13e commit 130a6d6
Showing 1 changed file with 10 additions and 12 deletions.
22 changes: 10 additions & 12 deletions src/components/Users/UserAvatar.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ import { formatDisplayName, sleep } from "@/Utils/utils";

export default function UserAvatar({
username,
refetchUserData: userDataRefetch,
refetchUserData,
}: {
username: string;
refetchUserData?: () => void;
Expand All @@ -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 <Loading />;
Expand All @@ -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);
}
Expand All @@ -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();
Expand Down

0 comments on commit 130a6d6

Please sign in to comment.