feat: implement undo friendship

This commit is contained in:
Zamitto 2024-07-25 23:03:11 -03:00
parent edf920fed3
commit 00c46bc981
6 changed files with 25 additions and 2 deletions

View file

@ -138,6 +138,7 @@ declare global {
/* Profile */
getMe: () => Promise<UserProfile | null>;
undoFriendship: (userId: string) => Promise<void>;
updateProfile: (
displayName: string,
newProfileImagePath: string | null

View file

@ -124,6 +124,10 @@ export function useUserDetails() {
[fetchFriendRequests]
);
const undoFriendship = (userId: string) => {
return window.electron.undoFriendship(userId);
};
const blockUser = (userId: string) => {
return window.electron.blockUser(userId);
};
@ -151,5 +155,6 @@ export function useUserDetails() {
updateFriendRequestState,
blockUser,
unblockUser,
undoFriendship,
};
}

View file

@ -50,6 +50,7 @@ export function UserContent({
fetchFriendRequests,
showFriendsModal,
updateFriendRequestState,
undoFriendship,
blockUser,
} = useUserDetails();
const { showSuccessToast, showErrorToast } = useToast();
@ -127,9 +128,11 @@ export function UserContent({
const handleUndoFriendship = (userRelation: UserRelation) => {
const userId =
userRelation.AId === userProfile.id ? userRelation.BId : userRelation.AId;
userRelation.AId === userDetails?.id
? userRelation.BId
: userRelation.AId;
updateFriendRequestState(userId, "CANCEL")
undoFriendship(userId)
.then(updateUserProfile)
.catch(() => {
showErrorToast(t("try_again"));