mirror of
https://github.com/hydralauncher/hydra.git
synced 2026-01-22 02:13:59 +00:00
feat: block and unblock events
This commit is contained in:
2
src/renderer/src/declaration.d.ts
vendored
2
src/renderer/src/declaration.d.ts
vendored
@@ -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,
|
||||
|
||||
@@ -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,
|
||||
};
|
||||
}
|
||||
|
||||
@@ -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>
|
||||
</>
|
||||
|
||||
Reference in New Issue
Block a user