mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-01-24 05:54: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 "./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";
|
||||||
|
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 */
|
/* 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"),
|
||||||
|
1
src/renderer/src/declaration.d.ts
vendored
1
src/renderer/src/declaration.d.ts
vendored
@ -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
|
||||||
|
@ -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,
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
@ -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"));
|
||||||
|
Loading…
Reference in New Issue
Block a user