mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-23 21:44:55 +03:00
feat: implement undo friendship
This commit is contained in:
parent
edf920fed3
commit
00c46bc981
@ -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";
|
||||
|
11
src/main/events/profile/undo-friendship.ts
Normal file
11
src/main/events/profile/undo-friendship.ts
Normal 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);
|
@ -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"),
|
||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -138,6 +138,7 @@ declare global {
|
||||
|
||||
/* Profile */
|
||||
getMe: () => Promise<UserProfile | null>;
|
||||
undoFriendship: (userId: string) => Promise<void>;
|
||||
updateProfile: (
|
||||
displayName: string,
|
||||
newProfileImagePath: string | null
|
||||
|
@ -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,
|
||||
};
|
||||
}
|
||||
|
@ -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"));
|
||||
|
Loading…
Reference in New Issue
Block a user