Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix: Profile Syncing #9994

Merged
merged 2 commits into from
Jan 16, 2025
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/components/Users/UserAvatar.tsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
import careConfig from "@careConfig";
import { useQueryClient } from "@tanstack/react-query";
import { useState } from "react";
import { useTranslation } from "react-i18next";
import { toast } from "sonner";
Expand Down Expand Up @@ -30,6 +31,7 @@ export default function UserAvatar({
const { t } = useTranslation();
const [editAvatar, setEditAvatar] = useState(false);
const authUser = useAuthUser();
const queryClient = useQueryClient();

const { data: userData, loading: isLoading } = useTanStackQueryInstead(
routes.getUserDetails,
Expand Down Expand Up @@ -58,6 +60,7 @@ export default function UserAvatar({
if (xhr.status === 200) {
await sleep(1000);
refetchUserData?.();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

now that we are invalidating the query, do we need to call refetchUserData?
check what the callees are doing with it and see if we can remove this.

await queryClient.invalidateQueries({ queryKey: ["currentUser"] });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

here too

toast.success(t("avatar_updated_success"));
setEditAvatar(false);
}
Expand All @@ -74,8 +77,9 @@ export default function UserAvatar({
pathParams: { username },
});
if (res?.ok) {
toast.success(t("profile_picture_deleted"));
refetchUserData?.();
await queryClient.invalidateQueries({ queryKey: ["currentUser"] });
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we can skip awaiting the query invalidation. toast can be shown right after the mutation has upload/delete has completed without waiting for invalidation to complete.

Suggested change
await queryClient.invalidateQueries({ queryKey: ["currentUser"] });
queryClient.invalidateQueries({ queryKey: ["currentUser"] });

toast.success(t("profile_picture_deleted"));
setEditAvatar(false);
} else {
onError();
Expand Down
Loading