mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-03-09 15:40:26 +00:00
feat: refactor hydra api
This commit is contained in:
parent
a81b016500
commit
6f70b529a2
9 changed files with 27 additions and 43 deletions
|
@ -82,23 +82,25 @@ export function useUserDetails() {
|
|||
[updateUserDetails]
|
||||
);
|
||||
|
||||
const sendFriendRequest = useCallback(async (userId: string) => {
|
||||
return window.electron.sendFriendRequest(userId);
|
||||
}, []);
|
||||
|
||||
const updateFriendRequests = useCallback(async () => {
|
||||
const friendRequests = await window.electron.getFriendRequests();
|
||||
dispatch(setFriendRequests(friendRequests));
|
||||
}, [dispatch]);
|
||||
|
||||
const sendFriendRequest = useCallback(
|
||||
async (userId: string) => {
|
||||
return window.electron
|
||||
.sendFriendRequest(userId)
|
||||
.then(() => updateFriendRequests());
|
||||
},
|
||||
[updateFriendRequests]
|
||||
);
|
||||
|
||||
const updateFriendRequestState = useCallback(
|
||||
async (userId: string, action: FriendRequestAction) => {
|
||||
return window.electron
|
||||
.updateFriendRequest(userId, action)
|
||||
.then(() => {})
|
||||
.catch(() => {
|
||||
console.log("falha no updateFriendsRequestState");
|
||||
});
|
||||
.then(() => updateFriendRequests());
|
||||
},
|
||||
[updateFriendRequests]
|
||||
);
|
||||
|
|
|
@ -22,12 +22,8 @@ export const UserAddFriendsModal = ({
|
|||
|
||||
const navigate = useNavigate();
|
||||
|
||||
const {
|
||||
sendFriendRequest,
|
||||
updateFriendRequests,
|
||||
updateFriendRequestState,
|
||||
friendRequests,
|
||||
} = useUserDetails();
|
||||
const { sendFriendRequest, updateFriendRequestState, friendRequests } =
|
||||
useUserDetails();
|
||||
|
||||
const { showSuccessToast, showErrorToast } = useToast();
|
||||
|
||||
|
@ -35,7 +31,6 @@ export const UserAddFriendsModal = ({
|
|||
setIsAddingFriend(true);
|
||||
sendFriendRequest(friendCode)
|
||||
.then(() => {
|
||||
updateFriendRequests();
|
||||
showSuccessToast(t("friend_request_sent"));
|
||||
})
|
||||
.catch(() => {
|
||||
|
@ -47,13 +42,11 @@ export const UserAddFriendsModal = ({
|
|||
};
|
||||
|
||||
const handleClickFriend = (userId: string) => {
|
||||
console.log("click friend");
|
||||
onClose();
|
||||
navigate(`/user/${userId}`);
|
||||
//onClose();
|
||||
//navigate(`/user/${userId}`);
|
||||
};
|
||||
|
||||
const handleClickSeeProfile = () => {
|
||||
console.log("click see profile");
|
||||
onClose();
|
||||
navigate(`/user/${friendCode}`);
|
||||
};
|
||||
|
@ -62,8 +55,6 @@ export const UserAddFriendsModal = ({
|
|||
event: React.MouseEvent,
|
||||
userId: string
|
||||
) => {
|
||||
console.log("cancel");
|
||||
event.preventDefault();
|
||||
updateFriendRequestState(userId, "CANCEL")
|
||||
.then(() => {
|
||||
console.log("sucesso");
|
||||
|
@ -77,8 +68,6 @@ export const UserAddFriendsModal = ({
|
|||
event: React.MouseEvent,
|
||||
userId: string
|
||||
) => {
|
||||
console.log("accept friend request");
|
||||
event.preventDefault();
|
||||
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
|
||||
showErrorToast("Falha ao aceitar convite");
|
||||
});
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue