mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: block and unblock events
This commit is contained in:
parent
304aa011ad
commit
edf920fed3
9 changed files with 55 additions and 3 deletions
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>
|
||||
</>
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue