From abdc9f6e982e9fba62bdd1e65b8715ba98f0fa22 Mon Sep 17 00:00:00 2001 From: Zamitto <167933696+zamitto@users.noreply.github.com> Date: Tue, 23 Jul 2024 21:24:16 -0300 Subject: [PATCH] feat: show friends component --- src/locales/en/translation.json | 3 +- src/locales/pt/translation.json | 3 +- ...riend-request.tsx => user-friend-item.tsx} | 102 +++++++++++------- .../user-friend-modal-add-friend.tsx | 8 +- .../user-friend-modal-list.tsx | 44 +++++++- .../user-friend-modal/user-friend-modal.tsx | 2 +- 6 files changed, 114 insertions(+), 48 deletions(-) rename src/renderer/src/pages/shared-modals/user-friend-modal/{user-friend-request.tsx => user-friend-item.tsx} (54%) diff --git a/src/locales/en/translation.json b/src/locales/en/translation.json index 3481dcb4..24ba8f0f 100644 --- a/src/locales/en/translation.json +++ b/src/locales/en/translation.json @@ -257,6 +257,7 @@ "request_received": "Request received", "accept_request": "Accept request", "ignore_request": "Ignore request", - "cancel_request": "Cancel request" + "cancel_request": "Cancel request", + "undo_friendship": "Undo friendship" } } diff --git a/src/locales/pt/translation.json b/src/locales/pt/translation.json index fc9fc5ec..ce4efd58 100644 --- a/src/locales/pt/translation.json +++ b/src/locales/pt/translation.json @@ -257,6 +257,7 @@ "request_received": "Pedido recebido", "accept_request": "Aceitar pedido", "ignore_request": "Ignorar pedido", - "cancel_request": "Cancelar pedido" + "cancel_request": "Cancelar pedido", + "undo_friendship": "Desfazer amizade" } } diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-request.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-item.tsx similarity index 54% rename from src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-request.tsx rename to src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-item.tsx index 4dd0d1e5..c7beab23 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-request.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-item.tsx @@ -8,35 +8,90 @@ import cn from "classnames"; import { SPACING_UNIT } from "@renderer/theme.css"; import { useTranslation } from "react-i18next"; -export interface UserFriendRequestProps { +export interface UserFriendItemProps { userId: string; profileImageUrl: string | null; displayName: string; - isRequestSent: boolean; + type: "SENT" | "RECEIVED" | "ACCEPTED"; onClickCancelRequest: (userId: string) => void; onClickAcceptRequest: (userId: string) => void; onClickRefuseRequest: (userId: string) => void; - onClickRequest: (userId: string) => void; + onClickItem: (userId: string) => void; } -export const UserFriendRequest = ({ +export const UserFriendItem = ({ userId, profileImageUrl, displayName, - isRequestSent, + type, onClickCancelRequest, onClickAcceptRequest, onClickRefuseRequest, - onClickRequest, -}: UserFriendRequestProps) => { + onClickItem, +}: UserFriendItemProps) => { const { t } = useTranslation("user_profile"); + const getRequestDescription = () => { + if (type === null) return null; + + return ( + + {type == "SENT" ? t("request_sent") : t("request_received")} + + ); + }; + + const getRequestActions = () => { + if (type === "SENT") { + return ( + + ); + } + + if (type === "RECEIVED") { + return ( + <> + + + + ); + } + + return ( + + ); + }; + return (
@@ -73,32 +126,7 @@ export const UserFriendRequest = ({ gap: `${SPACING_UNIT}px`, }} > - {isRequestSent ? ( - - ) : ( - <> - - - - )} + {getRequestActions()}
); diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx index 62290095..f71d4790 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-add-friend.tsx @@ -4,7 +4,7 @@ import { SPACING_UNIT } from "@renderer/theme.css"; import { useState } from "react"; import { useTranslation } from "react-i18next"; import { useNavigate } from "react-router-dom"; -import { UserFriendRequest } from "./user-friend-request"; +import { UserFriendItem } from "./user-friend-item"; export interface UserFriendModalAddFriendProps { closeModal: () => void; @@ -121,16 +121,16 @@ export const UserFriendModalAddFriend = ({

Pendentes

{friendRequests.map((request) => { return ( - ); })} diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-list.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-list.tsx index 83d7a6a0..2c639847 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-list.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal-list.tsx @@ -1,13 +1,22 @@ +import { SPACING_UNIT } from "@renderer/theme.css"; import { UserFriend } from "@types"; import { useEffect, useState } from "react"; +import { UserFriendItem } from "./user-friend-item"; +import { useNavigate } from "react-router-dom"; export interface UserFriendModalListProps { userId: string; + closeModal: () => void; } const pageSize = 12; -export const UserFriendModalList = ({ userId }: UserFriendModalListProps) => { +export const UserFriendModalList = ({ + userId, + closeModal, +}: UserFriendModalListProps) => { + const navigate = useNavigate(); + const [page, setPage] = useState(0); const [maxPage, setMaxPage] = useState(0); const [friends, setFriends] = useState([]); @@ -34,7 +43,34 @@ export const UserFriendModalList = ({ userId }: UserFriendModalListProps) => { loadNextPage(); }, [userId]); - return friends.map((friend) => { - return

{friend.displayName}

; - }); + const handleClickFriend = (userId: string) => { + closeModal(); + navigate(`/user/${userId}`); + }; + + return ( +
+ {friends.map((friend) => { + return ( + {}} + onClickCancelRequest={() => {}} + onClickRefuseRequest={() => {}} + onClickItem={handleClickFriend} + type={"ACCEPTED"} + key={friend.id} + /> + ); + })} +
+ ); }; diff --git a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal.tsx b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal.tsx index b0752de7..39a82ec4 100644 --- a/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal.tsx +++ b/src/renderer/src/pages/shared-modals/user-friend-modal/user-friend-modal.tsx @@ -43,7 +43,7 @@ export const UserFriendModal = ({ const renderTab = () => { if (currentTab == UserFriendModalTab.FriendsList) { - return ; + return ; } if (currentTab == UserFriendModalTab.AddFriend) {