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

@ -48,6 +48,7 @@ import "./user/unblock-user";
import "./user/get-user-friends";
import "./profile/get-friend-requests";
import "./profile/get-me";
import "./profile/undo-friendship";
import "./profile/update-friend-request";
import "./profile/update-profile";
import "./profile/send-friend-request";

View File

@ -0,0 +1,11 @@
import { registerEvent } from "../register-event";
import { HydraApi } from "@main/services";
const undoFriendship = async (
_event: Electron.IpcMainInvokeEvent,
userId: string
): Promise<void> => {
return HydraApi.delete(`/profile/friends/${userId}`);
};
registerEvent("undoFriendship", undoFriendship);

View File

@ -135,6 +135,8 @@ contextBridge.exposeInMainWorld("electron", {
/* Profile */
getMe: () => ipcRenderer.invoke("getMe"),
undoFriendship: (userId: string) =>
ipcRenderer.invoke("undoFriendship", userId),
updateProfile: (displayName: string, newProfileImagePath: string | null) =>
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),

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"));