Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

프로필 이미지 클릭 시 신고 모달 띄우기 #760

Merged
merged 9 commits into from
Mar 26, 2024
Merged
96 changes: 56 additions & 40 deletions packages/web/src/components/Chat/MessagesBody/MessageSet/index.tsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import { memo, useCallback } from "react";
import { memo, useCallback, useState } from "react";

import type { BotChat, LayoutType, UserChat } from "@/types/chat";

import { useValueRecoilState } from "@/hooks/useFetchRecoilState";

import { ModalChatReport } from "@/components/ModalPopup";
import ProfileImage from "@/components/User/ProfileImage";

import MessageAccount from "./MessageAccount";
Expand Down Expand Up @@ -58,12 +59,18 @@ type MessageSetProps = {
};

const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => {
const [isOpenReport, setIsOpenReport] = useState<boolean>(false);
const { oid: userOid } = useValueRecoilState("loginInfo") || {};

const onClickProfileImage = useCallback(() => setIsOpenReport(true), []);

const authorId = chats?.[0]?.authorId;
const authorProfileUrl =
"authorProfileUrl" in chats?.[0] ? chats?.[0].authorProfileUrl : "";
const authorName = "authorName" in chats?.[0] ? chats?.[0].authorName : "";

const isBot = authorId === "bot";

const style = {
position: "relative" as any,
display: "flex",
Expand Down Expand Up @@ -96,6 +103,9 @@ const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => {
alignItems: "flex-end",
gap: "4px",
};
const styleHover = {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

한번 밖에 안쓰이는거 같은데 그냥 태그 안에 넣어버려도 좋을 것 같아요

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

넵 반영했습니다!

cursor: "pointer",
};
const styleChat = useCallback(
(type: (UserChat | BotChat)["type"]) => ({
maxWidth: "max(75%, 210px)",
Expand Down Expand Up @@ -135,48 +145,54 @@ const MessageSet = ({ chats, layoutType, roomInfo }: MessageSetProps) => {
};

return (
<div css={style}>
<div css={styleProfileSection}>
{authorId !== userOid && (
<div
css={styleProfile}
onClick={() => {
/* @fixme @todo */
}}
>
{authorId === "bot" ? (
<TaxiIcon css={{ width: "100%", height: "100%" }} />
) : (
<ProfileImage url={authorProfileUrl} />
)}
</div>
)}
</div>
<div css={styleMessageSection}>
{authorId !== userOid && (
<div css={styleName} className="selectable">
{authorName}
</div>
)}
{chats.map((chat, index) => (
<div key={getChatUniquewKey(chat)} css={styleMessageWrap}>
<div css={styleChat(chat.type)}>
<MessageBody
type={chat.type}
content={chat.content}
roomInfo={roomInfo}
color={authorId === userOid ? theme.white : theme.black}
/>
<>
<div css={style}>
<div css={styleProfileSection}>
{authorId !== userOid && (
<div
css={{ ...styleProfile, ...(!isBot && styleHover) }}
onClick={() => !isBot && onClickProfileImage()}
>
{isBot ? (
<TaxiIcon css={{ width: "100%", height: "100%" }} />
) : (
<ProfileImage url={authorProfileUrl} />
)}
</div>
)}
</div>
<div css={styleMessageSection}>
{authorId !== userOid && (
<div css={styleName} className="selectable">
{authorName}
</div>
{index === chats.length - 1 && (
<div css={styleTime} className="selectable">
{dayjs(chat.time).format("H시 mm분")}
)}
{chats.map((chat, index) => (
<div key={getChatUniquewKey(chat)} css={styleMessageWrap}>
<div css={styleChat(chat.type)}>
<MessageBody
type={chat.type}
content={chat.content}
roomInfo={roomInfo}
color={authorId === userOid ? theme.white : theme.black}
/>
</div>
)}
</div>
))}
{index === chats.length - 1 && (
<div css={styleTime} className="selectable">
{dayjs(chat.time).format("H시 mm분")}
</div>
)}
</div>
))}
</div>
</div>
</div>
<ModalChatReport
roomInfo={roomInfo}
isOpen={isOpenReport}
onChangeIsOpen={setIsOpenReport}
userOid={authorId}
/>
</>
);
};

Expand Down