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", "ignore_request": "Ignore request",
"cancel_request": "Cancel request", "cancel_request": "Cancel request",
"undo_friendship": "Undo friendship", "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", "ignore_request": "Ignorar pedido",
"cancel_request": "Cancelar pedido", "cancel_request": "Cancelar pedido",
"undo_friendship": "Desfazer amizade", "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/open-auth-window";
import "./auth/get-session-hash"; import "./auth/get-session-hash";
import "./user/get-user"; import "./user/get-user";
import "./user/block-user";
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";

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 */ /* User */
getUser: (userId: string) => ipcRenderer.invoke("getUser", userId), 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) => getUserFriends: (userId: string, take: number, skip: number) =>
ipcRenderer.invoke("getUserFriends", userId, take, skip), ipcRenderer.invoke("getUserFriends", userId, take, skip),

View File

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

View File

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

View File

@ -50,6 +50,7 @@ export function UserContent({
fetchFriendRequests, fetchFriendRequests,
showFriendsModal, showFriendsModal,
updateFriendRequestState, updateFriendRequestState,
blockUser,
} = useUserDetails(); } = useUserDetails();
const { showSuccessToast, showErrorToast } = useToast(); 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) => { const handleCancelFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "CANCEL") updateFriendRequestState(userId, "CANCEL")
.then(updateUserProfile) .then(updateUserProfile)
@ -189,7 +201,7 @@ export function UserContent({
{t("add_friend")} {t("add_friend")}
</Button> </Button>
<Button theme="danger" onClick={() => {}}> <Button theme="danger" onClick={handleBlockUser}>
{t("block_user")} {t("block_user")}
</Button> </Button>
</> </>