feat: block and unblock events

This commit is contained in:
Zamitto 2024-07-25 20:08:53 -03:00
parent 304aa011ad
commit edf920fed3
9 changed files with 55 additions and 3 deletions

View File

@ -259,6 +259,7 @@
"ignore_request": "Ignore request",
"cancel_request": "Cancel request",
"undo_friendship": "Undo friendship",
"request_accepted": "Request accepted"
"request_accepted": "Request accepted",
"user_blocked_successfully": "User blocked successfully"
}
}

View File

@ -259,6 +259,7 @@
"ignore_request": "Ignorar pedido",
"cancel_request": "Cancelar pedido",
"undo_friendship": "Desfazer amizade",
"request_accepted": "Pedido de amizade aceito"
"request_accepted": "Pedido de amizade aceito",
"user_blocked_successfully": "Usuário bloqueado com sucesso"
}
}

View File

@ -43,6 +43,8 @@ import "./auth/sign-out";
import "./auth/open-auth-window";
import "./auth/get-session-hash";
import "./user/get-user";
import "./user/block-user";
import "./user/unblock-user";
import "./user/get-user-friends";
import "./profile/get-friend-requests";
import "./profile/get-me";

View File

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

View File

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

View File

@ -145,6 +145,8 @@ contextBridge.exposeInMainWorld("electron", {
/* User */
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId),
blockUser: (userId: string) => ipcRenderer.invoke("blockUser", userId),
unblockUser: (userId: string) => ipcRenderer.invoke("unblockUser", userId),
getUserFriends: (userId: string, take: number, skip: number) =>
ipcRenderer.invoke("getUserFriends", userId, take, skip),

View File

@ -128,6 +128,8 @@ declare global {
/* User */
getUser: (userId: string) => Promise<UserProfile | null>;
blockUser: (userId: string) => Promise<void>;
unblockUser: (userId: string) => Promise<void>;
getUserFriends: (
userId: string,
take: number,

View File

@ -124,6 +124,14 @@ export function useUserDetails() {
[fetchFriendRequests]
);
const blockUser = (userId: string) => {
return window.electron.blockUser(userId);
};
const unblockUser = (userId: string) => {
return window.electron.unblockUser(userId);
};
return {
userDetails,
profileBackground,
@ -141,5 +149,7 @@ export function useUserDetails() {
sendFriendRequest,
fetchFriendRequests,
updateFriendRequestState,
blockUser,
unblockUser,
};
}

View File

@ -50,6 +50,7 @@ export function UserContent({
fetchFriendRequests,
showFriendsModal,
updateFriendRequestState,
blockUser,
} = useUserDetails();
const { showSuccessToast, showErrorToast } = useToast();
@ -143,6 +144,17 @@ export function UserContent({
});
};
const handleBlockUser = () => {
blockUser(userProfile.id)
.then(() => {
showSuccessToast(t("user_blocked_successfully"));
navigate(-1);
})
.catch(() => {
showErrorToast(t("try_again"));
});
};
const handleCancelFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "CANCEL")
.then(updateUserProfile)
@ -189,7 +201,7 @@ export function UserContent({
{t("add_friend")}
</Button>
<Button theme="danger" onClick={() => {}}>
<Button theme="danger" onClick={handleBlockUser}>
{t("block_user")}
</Button>
</>