mirror of
https://github.com/hydralauncher/hydra.git
synced 2025-02-13 03:32:13 +00:00
fix: buttons on friend request item
This commit is contained in:
parent
6f70b529a2
commit
22b66149b3
4 changed files with 143 additions and 154 deletions
|
@ -25,13 +25,13 @@ export const UserAddFriendsModal = ({
|
||||||
const { sendFriendRequest, updateFriendRequestState, friendRequests } =
|
const { sendFriendRequest, updateFriendRequestState, friendRequests } =
|
||||||
useUserDetails();
|
useUserDetails();
|
||||||
|
|
||||||
const { showSuccessToast, showErrorToast } = useToast();
|
const { showErrorToast } = useToast();
|
||||||
|
|
||||||
const handleClickAddFriend = () => {
|
const handleClickAddFriend = () => {
|
||||||
setIsAddingFriend(true);
|
setIsAddingFriend(true);
|
||||||
sendFriendRequest(friendCode)
|
sendFriendRequest(friendCode)
|
||||||
.then(() => {
|
.then(() => {
|
||||||
showSuccessToast(t("friend_request_sent"));
|
setFriendCode("");
|
||||||
})
|
})
|
||||||
.catch(() => {
|
.catch(() => {
|
||||||
showErrorToast("Não foi possível enviar o pedido de amizade");
|
showErrorToast("Não foi possível enviar o pedido de amizade");
|
||||||
|
@ -41,133 +41,109 @@ export const UserAddFriendsModal = ({
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickFriend = (userId: string) => {
|
const handleClickRequest = (userId: string) => {
|
||||||
//onClose();
|
resetAndClose();
|
||||||
//navigate(`/user/${userId}`);
|
navigate(`/user/${userId}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickSeeProfile = () => {
|
const handleClickSeeProfile = () => {
|
||||||
onClose();
|
resetAndClose();
|
||||||
navigate(`/user/${friendCode}`);
|
navigate(`/user/${friendCode}`);
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickCancelFriendRequest = (
|
const handleClickCancelFriendRequest = (userId: string) => {
|
||||||
event: React.MouseEvent,
|
updateFriendRequestState(userId, "CANCEL").catch(() => {
|
||||||
userId: string
|
showErrorToast("Falha ao cancelar convite");
|
||||||
) => {
|
});
|
||||||
updateFriendRequestState(userId, "CANCEL")
|
|
||||||
.then(() => {
|
|
||||||
console.log("sucesso");
|
|
||||||
})
|
|
||||||
.catch(() => {
|
|
||||||
showErrorToast("Falha ao cancelar convite");
|
|
||||||
});
|
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickAcceptFriendRequest = (
|
const handleClickAcceptFriendRequest = (userId: string) => {
|
||||||
event: React.MouseEvent,
|
|
||||||
userId: string
|
|
||||||
) => {
|
|
||||||
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
|
updateFriendRequestState(userId, "ACCEPTED").catch(() => {
|
||||||
showErrorToast("Falha ao aceitar convite");
|
showErrorToast("Falha ao aceitar convite");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleClickRefuseFriendRequest = (
|
const handleClickRefuseFriendRequest = (userId: string) => {
|
||||||
event: React.MouseEvent,
|
|
||||||
userId: string
|
|
||||||
) => {
|
|
||||||
event.preventDefault();
|
|
||||||
updateFriendRequestState(userId, "REFUSED").catch(() => {
|
updateFriendRequestState(userId, "REFUSED").catch(() => {
|
||||||
showErrorToast("Falha ao recusar convite");
|
showErrorToast("Falha ao recusar convite");
|
||||||
});
|
});
|
||||||
};
|
};
|
||||||
|
|
||||||
const resetModal = () => {
|
const resetAndClose = () => {
|
||||||
setFriendCode("");
|
setFriendCode("");
|
||||||
};
|
|
||||||
|
|
||||||
const cleanFormAndClose = () => {
|
|
||||||
resetModal();
|
|
||||||
onClose();
|
onClose();
|
||||||
};
|
};
|
||||||
|
|
||||||
return (
|
return (
|
||||||
<>
|
<Modal visible={visible} title={t("add_friends")} onClose={resetAndClose}>
|
||||||
<Modal
|
<div
|
||||||
visible={visible}
|
style={{
|
||||||
title={t("add_friends")}
|
display: "flex",
|
||||||
onClose={cleanFormAndClose}
|
width: "500px",
|
||||||
|
flexDirection: "column",
|
||||||
|
gap: `${SPACING_UNIT * 2}px`,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<div
|
||||||
style={{
|
style={{
|
||||||
display: "flex",
|
display: "flex",
|
||||||
width: "500px",
|
flexDirection: "row",
|
||||||
|
justifyContent: "center",
|
||||||
|
alignItems: "center",
|
||||||
|
gap: `${SPACING_UNIT}px`,
|
||||||
|
}}
|
||||||
|
>
|
||||||
|
<TextField
|
||||||
|
label={t("friend_code")}
|
||||||
|
value={friendCode}
|
||||||
|
minLength={8}
|
||||||
|
maxLength={8}
|
||||||
|
containerProps={{ style: { width: "100%" } }}
|
||||||
|
onChange={(e) => setFriendCode(e.target.value)}
|
||||||
|
/>
|
||||||
|
<Button
|
||||||
|
disabled={isAddingFriend}
|
||||||
|
style={{ alignSelf: "end" }}
|
||||||
|
type="button"
|
||||||
|
onClick={handleClickAddFriend}
|
||||||
|
>
|
||||||
|
{isAddingFriend ? t("sending") : t("send")}
|
||||||
|
</Button>
|
||||||
|
<Button
|
||||||
|
onClick={handleClickSeeProfile}
|
||||||
|
disabled={isAddingFriend}
|
||||||
|
style={{ alignSelf: "end" }}
|
||||||
|
type="button"
|
||||||
|
>
|
||||||
|
{t("see_profile")}
|
||||||
|
</Button>
|
||||||
|
</div>
|
||||||
|
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
gap: `${SPACING_UNIT * 2}px`,
|
gap: `${SPACING_UNIT * 2}px`,
|
||||||
}}
|
}}
|
||||||
>
|
>
|
||||||
<div
|
<h3>Pendentes</h3>
|
||||||
style={{
|
{friendRequests?.map((request) => {
|
||||||
display: "flex",
|
return (
|
||||||
flexDirection: "row",
|
<UserFriendRequest
|
||||||
justifyContent: "center",
|
key={request.id}
|
||||||
alignItems: "center",
|
displayName={request.displayName}
|
||||||
gap: `${SPACING_UNIT}px`,
|
isRequestSent={request.type === "SENT"}
|
||||||
}}
|
profileImageUrl={request.profileImageUrl}
|
||||||
>
|
userId={request.id}
|
||||||
<TextField
|
onClickAcceptRequest={handleClickAcceptFriendRequest}
|
||||||
label={t("friend_code")}
|
onClickCancelRequest={handleClickCancelFriendRequest}
|
||||||
value={friendCode}
|
onClickRefuseRequest={handleClickRefuseFriendRequest}
|
||||||
minLength={8}
|
onClickRequest={handleClickRequest}
|
||||||
maxLength={8}
|
/>
|
||||||
containerProps={{ style: { width: "100%" } }}
|
);
|
||||||
onChange={(e) => setFriendCode(e.target.value)}
|
})}
|
||||||
/>
|
|
||||||
<Button
|
|
||||||
disabled={isAddingFriend}
|
|
||||||
style={{ alignSelf: "end" }}
|
|
||||||
type="button"
|
|
||||||
onClick={handleClickAddFriend}
|
|
||||||
>
|
|
||||||
{isAddingFriend ? t("sending") : t("send")}
|
|
||||||
</Button>
|
|
||||||
<Button
|
|
||||||
onClick={handleClickSeeProfile}
|
|
||||||
disabled={isAddingFriend}
|
|
||||||
style={{ alignSelf: "end" }}
|
|
||||||
type="button"
|
|
||||||
>
|
|
||||||
{t("see_profile")}
|
|
||||||
</Button>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
gap: `${SPACING_UNIT * 2}px`,
|
|
||||||
}}
|
|
||||||
>
|
|
||||||
<h3>Pendentes</h3>
|
|
||||||
{friendRequests?.map((request) => {
|
|
||||||
return (
|
|
||||||
<UserFriendRequest
|
|
||||||
key={request.id}
|
|
||||||
displayName={request.displayName}
|
|
||||||
isRequestSent={request.type === "SENT"}
|
|
||||||
profileImageUrl={request.profileImageUrl}
|
|
||||||
userId={request.id}
|
|
||||||
onClickAcceptRequest={handleClickAcceptFriendRequest}
|
|
||||||
onClickCancelRequest={handleClickCancelFriendRequest}
|
|
||||||
onClickRefuseRequest={handleClickRefuseFriendRequest}
|
|
||||||
onClickRequest={handleClickFriend}
|
|
||||||
/>
|
|
||||||
);
|
|
||||||
})}
|
|
||||||
</div>
|
|
||||||
</div>
|
</div>
|
||||||
</Modal>
|
</div>
|
||||||
</>
|
</Modal>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -375,7 +375,7 @@ export function UserContent({
|
||||||
<button
|
<button
|
||||||
key={friend.id}
|
key={friend.id}
|
||||||
className={cn(
|
className={cn(
|
||||||
styles.friendListItem,
|
styles.friendListContainer,
|
||||||
styles.profileContentBox
|
styles.profileContentBox
|
||||||
)}
|
)}
|
||||||
onClick={() => handleOnClickFriend(friend.id)}
|
onClick={() => handleOnClickFriend(friend.id)}
|
||||||
|
|
|
@ -11,9 +11,9 @@ export interface UserFriendRequestProps {
|
||||||
profileImageUrl: string | null;
|
profileImageUrl: string | null;
|
||||||
displayName: string;
|
displayName: string;
|
||||||
isRequestSent: boolean;
|
isRequestSent: boolean;
|
||||||
onClickCancelRequest: (event: React.MouseEvent, userId: string) => void;
|
onClickCancelRequest: (userId: string) => void;
|
||||||
onClickAcceptRequest: (event: React.MouseEvent, userId: string) => void;
|
onClickAcceptRequest: (userId: string) => void;
|
||||||
onClickRefuseRequest: (event: React.MouseEvent, userId: string) => void;
|
onClickRefuseRequest: (userId: string) => void;
|
||||||
onClickRequest: (userId: string) => void;
|
onClickRequest: (userId: string) => void;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,57 +28,62 @@ export const UserFriendRequest = ({
|
||||||
onClickRequest,
|
onClickRequest,
|
||||||
}: UserFriendRequestProps) => {
|
}: UserFriendRequestProps) => {
|
||||||
return (
|
return (
|
||||||
<button
|
<div className={cn(styles.friendListContainer, styles.profileContentBox)}>
|
||||||
type="button"
|
<button
|
||||||
className={cn(styles.friendListItem, styles.profileContentBox)}
|
type="button"
|
||||||
onClick={() => onClickRequest(userId)}
|
className={styles.friendListButton}
|
||||||
>
|
onClick={() => onClickRequest(userId)}
|
||||||
<div className={styles.friendAvatarContainer}>
|
|
||||||
{profileImageUrl ? (
|
|
||||||
<img
|
|
||||||
className={styles.profileAvatar}
|
|
||||||
alt={displayName}
|
|
||||||
src={profileImageUrl}
|
|
||||||
/>
|
|
||||||
) : (
|
|
||||||
<PersonIcon size={24} />
|
|
||||||
)}
|
|
||||||
</div>
|
|
||||||
<div
|
|
||||||
style={{
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "column",
|
|
||||||
alignItems: "flex-start",
|
|
||||||
flex: "1",
|
|
||||||
minWidth: 0,
|
|
||||||
}}
|
|
||||||
>
|
>
|
||||||
<p className={styles.friendListDisplayName}>{displayName}</p>
|
<div className={styles.friendAvatarContainer}>
|
||||||
<small>{isRequestSent ? "Pedido enviado" : "Pedido recebido"}</small>
|
{profileImageUrl ? (
|
||||||
</div>
|
<img
|
||||||
{isRequestSent ? (
|
className={styles.profileAvatar}
|
||||||
<button
|
alt={displayName}
|
||||||
className={styles.cancelRequestButton}
|
src={profileImageUrl}
|
||||||
onClick={(e) => onClickCancelRequest(e, userId)}
|
/>
|
||||||
|
) : (
|
||||||
|
<PersonIcon size={24} />
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
<div
|
||||||
|
style={{
|
||||||
|
display: "flex",
|
||||||
|
flexDirection: "column",
|
||||||
|
alignItems: "flex-start",
|
||||||
|
flex: "1",
|
||||||
|
minWidth: 0,
|
||||||
|
}}
|
||||||
>
|
>
|
||||||
<XCircleIcon size={28} />
|
<p className={styles.friendListDisplayName}>{displayName}</p>
|
||||||
</button>
|
<small>{isRequestSent ? "Pedido enviado" : "Pedido recebido"}</small>
|
||||||
) : (
|
</div>
|
||||||
<>
|
</button>
|
||||||
<button
|
|
||||||
className={styles.acceptRequestButton}
|
<div style={{ position: "absolute", right: "8px" }}>
|
||||||
onClick={(e) => onClickAcceptRequest(e, userId)}
|
{isRequestSent ? (
|
||||||
>
|
|
||||||
<CheckCircleIcon size={28} />
|
|
||||||
</button>
|
|
||||||
<button
|
<button
|
||||||
className={styles.cancelRequestButton}
|
className={styles.cancelRequestButton}
|
||||||
onClick={(e) => onClickRefuseRequest(e, userId)}
|
onClick={() => onClickCancelRequest(userId)}
|
||||||
>
|
>
|
||||||
<XCircleIcon size={28} />
|
<XCircleIcon size={28} />
|
||||||
</button>
|
</button>
|
||||||
</>
|
) : (
|
||||||
)}
|
<>
|
||||||
</button>
|
<button
|
||||||
|
className={styles.acceptRequestButton}
|
||||||
|
onClick={() => onClickAcceptRequest(userId)}
|
||||||
|
>
|
||||||
|
<CheckCircleIcon size={28} />
|
||||||
|
</button>
|
||||||
|
<button
|
||||||
|
className={styles.cancelRequestButton}
|
||||||
|
onClick={() => onClickRefuseRequest(userId)}
|
||||||
|
>
|
||||||
|
<XCircleIcon size={28} />
|
||||||
|
</button>
|
||||||
|
</>
|
||||||
|
)}
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
);
|
);
|
||||||
};
|
};
|
||||||
|
|
|
@ -178,21 +178,29 @@ export const gameListItem = style({
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
export const friendListItem = style({
|
export const friendListContainer = style({
|
||||||
color: vars.color.body,
|
|
||||||
display: "flex",
|
|
||||||
flexDirection: "row",
|
|
||||||
gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`,
|
|
||||||
width: "100%",
|
width: "100%",
|
||||||
height: "54px",
|
height: "54px",
|
||||||
padding: "0 8px",
|
|
||||||
transition: "all ease 0.2s",
|
transition: "all ease 0.2s",
|
||||||
cursor: "pointer",
|
position: "relative",
|
||||||
":hover": {
|
":hover": {
|
||||||
backgroundColor: "rgba(255, 255, 255, 0.15)",
|
backgroundColor: "rgba(255, 255, 255, 0.15)",
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
|
|
||||||
|
export const friendListButton = style({
|
||||||
|
display: "flex",
|
||||||
|
alignItems: "center",
|
||||||
|
position: "absolute",
|
||||||
|
cursor: "pointer",
|
||||||
|
height: "100%",
|
||||||
|
width: "100%",
|
||||||
|
flexDirection: "row",
|
||||||
|
color: vars.color.body,
|
||||||
|
gap: `${SPACING_UNIT + SPACING_UNIT / 2}px`,
|
||||||
|
padding: "0 8px",
|
||||||
|
});
|
||||||
|
|
||||||
export const gameInformation = style({
|
export const gameInformation = style({
|
||||||
display: "flex",
|
display: "flex",
|
||||||
flexDirection: "column",
|
flexDirection: "column",
|
||||||
|
|
Loading…
Reference in a new issue