feat: show friends component

This commit is contained in:
Zamitto 2024-07-23 21:24:16 -03:00
parent a196b91cb9
commit abdc9f6e98
6 changed files with 114 additions and 48 deletions

View File

@ -257,6 +257,7 @@
"request_received": "Request received", "request_received": "Request received",
"accept_request": "Accept request", "accept_request": "Accept request",
"ignore_request": "Ignore request", "ignore_request": "Ignore request",
"cancel_request": "Cancel request" "cancel_request": "Cancel request",
"undo_friendship": "Undo friendship"
} }
} }

View File

@ -257,6 +257,7 @@
"request_received": "Pedido recebido", "request_received": "Pedido recebido",
"accept_request": "Aceitar pedido", "accept_request": "Aceitar pedido",
"ignore_request": "Ignorar pedido", "ignore_request": "Ignorar pedido",
"cancel_request": "Cancelar pedido" "cancel_request": "Cancelar pedido",
"undo_friendship": "Desfazer amizade"
} }
} }

View File

@ -8,35 +8,90 @@ import cn from "classnames";
import { SPACING_UNIT } from "@renderer/theme.css"; import { SPACING_UNIT } from "@renderer/theme.css";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
export interface UserFriendRequestProps { export interface UserFriendItemProps {
userId: string; userId: string;
profileImageUrl: string | null; profileImageUrl: string | null;
displayName: string; displayName: string;
isRequestSent: boolean; type: "SENT" | "RECEIVED" | "ACCEPTED";
onClickCancelRequest: (userId: string) => void; onClickCancelRequest: (userId: string) => void;
onClickAcceptRequest: (userId: string) => void; onClickAcceptRequest: (userId: string) => void;
onClickRefuseRequest: (userId: string) => void; onClickRefuseRequest: (userId: string) => void;
onClickRequest: (userId: string) => void; onClickItem: (userId: string) => void;
} }
export const UserFriendRequest = ({ export const UserFriendItem = ({
userId, userId,
profileImageUrl, profileImageUrl,
displayName, displayName,
isRequestSent, type,
onClickCancelRequest, onClickCancelRequest,
onClickAcceptRequest, onClickAcceptRequest,
onClickRefuseRequest, onClickRefuseRequest,
onClickRequest, onClickItem,
}: UserFriendRequestProps) => { }: UserFriendItemProps) => {
const { t } = useTranslation("user_profile"); const { t } = useTranslation("user_profile");
const getRequestDescription = () => {
if (type === null) return null;
return (
<small>
{type == "SENT" ? t("request_sent") : t("request_received")}
</small>
);
};
const getRequestActions = () => {
if (type === "SENT") {
return (
<button
className={styles.cancelRequestButton}
onClick={() => onClickCancelRequest(userId)}
title={t("cancel_request")}
>
<XCircleIcon size={28} />
</button>
);
}
if (type === "RECEIVED") {
return (
<>
<button
className={styles.acceptRequestButton}
onClick={() => onClickAcceptRequest(userId)}
title={t("accept_request")}
>
<CheckCircleIcon size={28} />
</button>
<button
className={styles.cancelRequestButton}
onClick={() => onClickRefuseRequest(userId)}
title={t("ignore_request")}
>
<XCircleIcon size={28} />
</button>
</>
);
}
return (
<button
className={styles.cancelRequestButton}
onClick={() => onClickCancelRequest(userId)}
title={t("undo_friendship")}
>
<XCircleIcon size={28} />
</button>
);
};
return ( return (
<div className={cn(styles.friendListContainer, styles.profileContentBox)}> <div className={cn(styles.friendListContainer, styles.profileContentBox)}>
<button <button
type="button" type="button"
className={styles.friendListButton} className={styles.friendListButton}
onClick={() => onClickRequest(userId)} onClick={() => onClickItem(userId)}
> >
<div className={styles.friendAvatarContainer}> <div className={styles.friendAvatarContainer}>
{profileImageUrl ? ( {profileImageUrl ? (
@ -59,9 +114,7 @@ export const UserFriendRequest = ({
}} }}
> >
<p className={styles.friendListDisplayName}>{displayName}</p> <p className={styles.friendListDisplayName}>{displayName}</p>
<small> {getRequestDescription()}
{isRequestSent ? t("request_sent") : t("request_received")}
</small>
</div> </div>
</button> </button>
@ -73,32 +126,7 @@ export const UserFriendRequest = ({
gap: `${SPACING_UNIT}px`, gap: `${SPACING_UNIT}px`,
}} }}
> >
{isRequestSent ? ( {getRequestActions()}
<button
className={styles.cancelRequestButton}
onClick={() => onClickCancelRequest(userId)}
title={t("cancel_request")}
>
<XCircleIcon size={28} />
</button>
) : (
<>
<button
className={styles.acceptRequestButton}
onClick={() => onClickAcceptRequest(userId)}
title={t("accept_request")}
>
<CheckCircleIcon size={28} />
</button>
<button
className={styles.cancelRequestButton}
onClick={() => onClickRefuseRequest(userId)}
title={t("ignore_request")}
>
<XCircleIcon size={28} />
</button>
</>
)}
</div> </div>
</div> </div>
); );

View File

@ -4,7 +4,7 @@ import { SPACING_UNIT } from "@renderer/theme.css";
import { useState } from "react"; import { useState } from "react";
import { useTranslation } from "react-i18next"; import { useTranslation } from "react-i18next";
import { useNavigate } from "react-router-dom"; import { useNavigate } from "react-router-dom";
import { UserFriendRequest } from "./user-friend-request"; import { UserFriendItem } from "./user-friend-item";
export interface UserFriendModalAddFriendProps { export interface UserFriendModalAddFriendProps {
closeModal: () => void; closeModal: () => void;
@ -121,16 +121,16 @@ export const UserFriendModalAddFriend = ({
<h3>Pendentes</h3> <h3>Pendentes</h3>
{friendRequests.map((request) => { {friendRequests.map((request) => {
return ( return (
<UserFriendRequest <UserFriendItem
key={request.id} key={request.id}
displayName={request.displayName} displayName={request.displayName}
isRequestSent={request.type === "SENT"} type={request.type}
profileImageUrl={request.profileImageUrl} profileImageUrl={request.profileImageUrl}
userId={request.id} userId={request.id}
onClickAcceptRequest={handleAcceptFriendRequest} onClickAcceptRequest={handleAcceptFriendRequest}
onClickCancelRequest={handleCancelFriendRequest} onClickCancelRequest={handleCancelFriendRequest}
onClickRefuseRequest={handleRefuseFriendRequest} onClickRefuseRequest={handleRefuseFriendRequest}
onClickRequest={handleClickRequest} onClickItem={handleClickRequest}
/> />
); );
})} })}

View File

@ -1,13 +1,22 @@
import { SPACING_UNIT } from "@renderer/theme.css";
import { UserFriend } from "@types"; import { UserFriend } from "@types";
import { useEffect, useState } from "react"; import { useEffect, useState } from "react";
import { UserFriendItem } from "./user-friend-item";
import { useNavigate } from "react-router-dom";
export interface UserFriendModalListProps { export interface UserFriendModalListProps {
userId: string; userId: string;
closeModal: () => void;
} }
const pageSize = 12; const pageSize = 12;
export const UserFriendModalList = ({ userId }: UserFriendModalListProps) => { export const UserFriendModalList = ({
userId,
closeModal,
}: UserFriendModalListProps) => {
const navigate = useNavigate();
const [page, setPage] = useState(0); const [page, setPage] = useState(0);
const [maxPage, setMaxPage] = useState(0); const [maxPage, setMaxPage] = useState(0);
const [friends, setFriends] = useState<UserFriend[]>([]); const [friends, setFriends] = useState<UserFriend[]>([]);
@ -34,7 +43,34 @@ export const UserFriendModalList = ({ userId }: UserFriendModalListProps) => {
loadNextPage(); loadNextPage();
}, [userId]); }, [userId]);
return friends.map((friend) => { const handleClickFriend = (userId: string) => {
return <p key={friend.id}>{friend.displayName}</p>; closeModal();
}); navigate(`/user/${userId}`);
};
return (
<div
style={{
display: "flex",
flexDirection: "column",
gap: `${SPACING_UNIT * 2}px`,
}}
>
{friends.map((friend) => {
return (
<UserFriendItem
userId={friend.id}
displayName={friend.displayName}
profileImageUrl={friend.profileImageUrl}
onClickAcceptRequest={() => {}}
onClickCancelRequest={() => {}}
onClickRefuseRequest={() => {}}
onClickItem={handleClickFriend}
type={"ACCEPTED"}
key={friend.id}
/>
);
})}
</div>
);
}; };

View File

@ -43,7 +43,7 @@ export const UserFriendModal = ({
const renderTab = () => { const renderTab = () => {
if (currentTab == UserFriendModalTab.FriendsList) { if (currentTab == UserFriendModalTab.FriendsList) {
return <UserFriendModalList userId={userId} />; return <UserFriendModalList userId={userId} closeModal={onClose} />;
} }
if (currentTab == UserFriendModalTab.AddFriend) { if (currentTab == UserFriendModalTab.AddFriend) {