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 "./user/get-user-friends";
import "./profile/get-friend-requests"; import "./profile/get-friend-requests";
import "./profile/get-me"; import "./profile/get-me";
import "./profile/undo-friendship";
import "./profile/update-friend-request"; import "./profile/update-friend-request";
import "./profile/update-profile"; import "./profile/update-profile";
import "./profile/send-friend-request"; 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 */ /* Profile */
getMe: () => ipcRenderer.invoke("getMe"), getMe: () => ipcRenderer.invoke("getMe"),
undoFriendship: (userId: string) =>
ipcRenderer.invoke("undoFriendship", userId),
updateProfile: (displayName: string, newProfileImagePath: string | null) => updateProfile: (displayName: string, newProfileImagePath: string | null) =>
ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath), ipcRenderer.invoke("updateProfile", displayName, newProfileImagePath),
getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"), getFriendRequests: () => ipcRenderer.invoke("getFriendRequests"),

View File

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

View File

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

View File

@ -50,6 +50,7 @@ export function UserContent({
fetchFriendRequests, fetchFriendRequests,
showFriendsModal, showFriendsModal,
updateFriendRequestState, updateFriendRequestState,
undoFriendship,
blockUser, blockUser,
} = useUserDetails(); } = useUserDetails();
const { showSuccessToast, showErrorToast } = useToast(); const { showSuccessToast, showErrorToast } = useToast();
@ -127,9 +128,11 @@ export function UserContent({
const handleUndoFriendship = (userRelation: UserRelation) => { const handleUndoFriendship = (userRelation: UserRelation) => {
const userId = 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) .then(updateUserProfile)
.catch(() => { .catch(() => {
showErrorToast(t("try_again")); showErrorToast(t("try_again"));