feat: rename functions

This commit is contained in:
Zamitto 2024-07-21 20:49:37 -03:00
parent 6b8f2e6978
commit e642bf71b1
4 changed files with 41 additions and 22 deletions

View File

@ -42,7 +42,7 @@ export function App() {
const {
isFriendsModalVisible,
friendRequetsModalTab,
updateFriendRequests,
fetchFriendRequests,
hideFriendsModal,
} = useUserDetails();
@ -104,7 +104,7 @@ export function App() {
fetchUserDetails().then((response) => {
if (response) {
updateUserDetails(response);
updateFriendRequests();
fetchFriendRequests();
}
});
}, [fetchUserDetails, updateUserDetails, dispatch]);
@ -113,7 +113,7 @@ export function App() {
fetchUserDetails().then((response) => {
if (response) {
updateUserDetails(response);
updateFriendRequests();
fetchFriendRequests();
showSuccessToast(t("successfully_signed_in"));
}
});

View File

@ -84,7 +84,7 @@ export function useUserDetails() {
[updateUserDetails]
);
const updateFriendRequests = useCallback(async () => {
const fetchFriendRequests = useCallback(async () => {
const friendRequests = await window.electron.getFriendRequests();
dispatch(setFriendRequests(friendRequests));
}, [dispatch]);
@ -92,7 +92,7 @@ export function useUserDetails() {
const showFriendsModal = useCallback(
(tab: UserFriendModalTab) => {
dispatch(setFriendsModalVisible(tab));
updateFriendRequests();
fetchFriendRequests();
},
[dispatch]
);
@ -105,18 +105,18 @@ export function useUserDetails() {
async (userId: string) => {
return window.electron
.sendFriendRequest(userId)
.then(() => updateFriendRequests());
.then(() => fetchFriendRequests());
},
[updateFriendRequests]
[fetchFriendRequests]
);
const updateFriendRequestState = useCallback(
async (userId: string, action: FriendRequestAction) => {
return window.electron
.updateFriendRequest(userId, action)
.then(() => updateFriendRequests());
.then(() => fetchFriendRequests());
},
[updateFriendRequests]
[fetchFriendRequests]
);
return {
@ -133,7 +133,7 @@ export function useUserDetails() {
updateUserDetails,
patchUser,
sendFriendRequest,
updateFriendRequests,
fetchFriendRequests,
updateFriendRequestState,
};
}

View File

@ -56,19 +56,19 @@ export const UserFriendModalAddFriend = ({
navigate(`/user/${friendCode}`);
};
const handleClickCancelFriendRequest = (userId: string) => {
const handleCancelFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "CANCEL").catch(() => {
showErrorToast("Falha ao cancelar convite");
});
};
const handleClickAcceptFriendRequest = (userId: string) => {
const handleAcceptFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
showErrorToast("Falha ao aceitar convite");
});
};
const handleClickRefuseFriendRequest = (userId: string) => {
const handleRefuseFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "REFUSED").catch(() => {
showErrorToast("Falha ao recusar convite");
});
@ -127,9 +127,9 @@ export const UserFriendModalAddFriend = ({
isRequestSent={request.type === "SENT"}
profileImageUrl={request.profileImageUrl}
userId={request.id}
onClickAcceptRequest={handleClickAcceptFriendRequest}
onClickCancelRequest={handleClickCancelFriendRequest}
onClickRefuseRequest={handleClickRefuseFriendRequest}
onClickAcceptRequest={handleAcceptFriendRequest}
onClickCancelRequest={handleCancelFriendRequest}
onClickRefuseRequest={handleRefuseFriendRequest}
onClickRequest={handleClickRequest}
/>
);

View File

@ -47,10 +47,11 @@ export function UserContent({
profileBackground,
friendRequests,
signOut,
updateFriendRequests,
fetchFriendRequests,
showFriendsModal,
updateFriendRequestState,
} = useUserDetails();
const { showSuccessToast } = useToast();
const { showSuccessToast, showErrorToast } = useToast();
const [profileContentBoxBackground, setProfileContentBoxBackground] =
useState<string | undefined>();
@ -106,7 +107,7 @@ export function UserContent({
const isMe = userDetails?.id == userProfile.id;
useEffect(() => {
if (isMe) updateFriendRequests();
if (isMe) fetchFriendRequests();
}, [isMe]);
useEffect(() => {
@ -123,6 +124,24 @@ export function UserContent({
}
}, [profileBackground, isMe]);
const handleCancelFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "CANCEL").catch(() => {
showErrorToast("Falha ao cancelar convite");
});
};
const handleAcceptFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
showErrorToast("Falha ao aceitar convite");
});
};
const handleRefuseFriendRequest = (userId: string) => {
updateFriendRequestState(userId, "REFUSED").catch(() => {
showErrorToast("Falha ao recusar convite");
});
};
const getProfileActions = () => {
if (isMe) {
return (
@ -162,14 +181,14 @@ export function UserContent({
<Button
theme="outline"
className={styles.acceptRequestButton}
onClick={() => {}}
onClick={() => handleAcceptFriendRequest(friendRequest.id)}
>
<CheckCircleIcon size={28} /> {t("accept_request")}
</Button>
<Button
theme="outline"
className={styles.cancelRequestButton}
onClick={() => {}}
onClick={() => handleRefuseFriendRequest(friendRequest.id)}
>
<XCircleIcon size={28} /> {t("ignore_request")}
</Button>
@ -181,7 +200,7 @@ export function UserContent({
<Button
theme="outline"
className={styles.cancelRequestButton}
onClick={() => {}}
onClick={() => handleCancelFriendRequest(friendRequest.id)}
>
<XCircleIcon size={28} /> {t("cancel_request")}
</Button>