reloading user profile on update

This commit is contained in:
Zamitto 2024-06-18 12:29:58 -03:00
parent 30fb588d3c
commit 9c37711bbf
2 changed files with 25 additions and 5 deletions

View file

@ -17,9 +17,13 @@ const MAX_MINUTES_TO_SHOW_IN_PLAYTIME = 120;
export interface ProfileContentProps { export interface ProfileContentProps {
userProfile: UserProfile; userProfile: UserProfile;
updateUserProfile: () => void;
} }
export function UserContent({ userProfile }: ProfileContentProps) { export function UserContent({
userProfile,
updateUserProfile,
}: ProfileContentProps) {
const { t, i18n } = useTranslation("user_profile"); const { t, i18n } = useTranslation("user_profile");
const { userDetails, profileBackground, signOut, updateUser } = const { userDetails, profileBackground, signOut, updateUser } =
@ -67,6 +71,11 @@ export function UserContent({ userProfile }: ProfileContentProps) {
navigate("/"); navigate("/");
}; };
const handleUpdateUserProfile = async () => {
updateUser();
updateUserProfile();
};
const isMe = userDetails?.id == userProfile.id; const isMe = userDetails?.id == userProfile.id;
const profileContentBoxBackground = useMemo(() => { const profileContentBoxBackground = useMemo(() => {
@ -80,7 +89,7 @@ export function UserContent({ userProfile }: ProfileContentProps) {
<UserEditProfileModal <UserEditProfileModal
visible={showEditProfileModal} visible={showEditProfileModal}
onClose={() => setShowEditProfileModal(false)} onClose={() => setShowEditProfileModal(false)}
updateUser={updateUser} updateUser={handleUpdateUserProfile}
userProfile={userProfile} userProfile={userProfile}
/> />

View file

@ -1,5 +1,5 @@
import { UserProfile } from "@types"; import { UserProfile } from "@types";
import { useEffect, useState } from "react"; import { useCallback, useEffect, useState } from "react";
import { useParams } from "react-router-dom"; import { useParams } from "react-router-dom";
import { setHeaderTitle } from "@renderer/features"; import { setHeaderTitle } from "@renderer/features";
import { useAppDispatch } from "@renderer/hooks"; import { useAppDispatch } from "@renderer/hooks";
@ -15,7 +15,7 @@ export const User = () => {
const dispatch = useAppDispatch(); const dispatch = useAppDispatch();
useEffect(() => { const getUserProfile = useCallback(() => {
window.electron.getUser(userId!).then((userProfile) => { window.electron.getUser(userId!).then((userProfile) => {
if (userProfile) { if (userProfile) {
dispatch(setHeaderTitle(userProfile.displayName)); dispatch(setHeaderTitle(userProfile.displayName));
@ -24,11 +24,22 @@ export const User = () => {
}); });
}, [dispatch, userId]); }, [dispatch, userId]);
useEffect(() => {
getUserProfile();
}, [getUserProfile]);
const handleUpdateProfile = () => {
getUserProfile();
};
return ( return (
<SkeletonTheme baseColor={vars.color.background} highlightColor="#444"> <SkeletonTheme baseColor={vars.color.background} highlightColor="#444">
<div className={styles.wrapper}> <div className={styles.wrapper}>
{userProfile ? ( {userProfile ? (
<UserContent userProfile={userProfile} /> <UserContent
userProfile={userProfile}
updateUserProfile={handleUpdateProfile}
/>
) : ( ) : (
<UserSkeleton /> <UserSkeleton />
)} )}