Skip to content

Commit 43d87c8

Browse files
authored
Merge pull request #282 from Soohyuniii/feature/오픈채팅-UI-개발
feat: 오픈채팅(주제별채팅) 기능 홈 및 폼 UI 개발
2 parents e3e09a8 + da7ab00 commit 43d87c8

File tree

7 files changed

+363
-169
lines changed

7 files changed

+363
-169
lines changed

.nvmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
18.20.7

src/components/Profile.tsx

Lines changed: 97 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,27 @@ import { VirtualFriend } from "@/types/virtualFreind";
55
import trackClickEvent from "@/utils/trackClickEvent";
66

77
interface ProfileProps {
8-
info: VirtualFriend;
9-
deleteIndex: number;
10-
setVirtualFriendList: React.Dispatch<SetStateAction<VirtualFriend[]>>;
8+
mode: "friend" | "topic";
9+
info?: VirtualFriend;
10+
deleteIndex?: number;
11+
setVirtualFriendList?: React.Dispatch<SetStateAction<VirtualFriend[]>>;
12+
topicData?: {
13+
chatTitle: string;
14+
description: string;
15+
};
1116
}
12-
const Profile = ({ info, deleteIndex, setVirtualFriendList }: ProfileProps) => {
17+
const Profile = ({
18+
mode,
19+
info,
20+
deleteIndex,
21+
setVirtualFriendList,
22+
topicData
23+
}: ProfileProps) => {
1324
const navigate = useNavigate();
1425

1526
const handleDelete = async () => {
27+
if (!info || !setVirtualFriendList || deleteIndex === undefined) return;
28+
1629
trackClickEvent("홈", "친구 - 삭제");
1730
const res = await authInstance.delete(
1831
`/api/virtual-friend/${info.virtualFriendId}`
@@ -25,49 +38,104 @@ const Profile = ({ info, deleteIndex, setVirtualFriendList }: ProfileProps) => {
2538
};
2639

2740
const handleNavigate = () => {
28-
trackClickEvent("홈", "친구 - 바로 대화하기");
29-
navigate("/chat", {
30-
state: {
31-
mode: "virtualFriend",
32-
mbti: info.mbti,
33-
id: info.virtualFriendId,
34-
name: info.virtualFriendName
35-
}
36-
});
41+
if (mode === "friend" && info) {
42+
trackClickEvent("홈", "친구 - 바로 대화하기");
43+
navigate("/chat", {
44+
state: {
45+
mode: "virtualFriend",
46+
mbti: info.mbti,
47+
id: info.virtualFriendId,
48+
name: info.virtualFriendName
49+
}
50+
});
51+
} else if (mode === "topic" && topicData) {
52+
trackClickEvent("홈", "주제별 대화방"); //FIXME: 기획 내용 정해지면 수정
53+
navigate("/select-info", {
54+
state: {
55+
type: "topicChat",
56+
chatTitle: topicData.chatTitle,
57+
description: topicData.description
58+
}
59+
});
60+
}
61+
};
62+
63+
const getImageSrc = () => {
64+
if (mode === "friend" && info) {
65+
return `/public/image/${info.mbti}_profile.png`;
66+
} else if (mode === "topic" && topicData) {
67+
//FIXME: 디자인 정해지면 수정
68+
return "/icon/starbubble.svg";
69+
}
70+
return "";
71+
};
72+
73+
const getTitle = () => {
74+
if (mode === "friend" && info) {
75+
return info.virtualFriendName;
76+
} else if (mode === "topic" && topicData) {
77+
return topicData.chatTitle;
78+
}
79+
return "";
80+
};
81+
82+
const getSubtitle = () => {
83+
if (mode === "friend" && info) {
84+
return info.mbti;
85+
} else if (mode === "topic" && topicData) {
86+
return "";
87+
}
88+
return "";
89+
};
90+
91+
const getDescription = () => {
92+
if (mode === "friend" && info) {
93+
return `${info.virtualFriendAge} · ${info.virtualFriendSex} · ${info.virtualFriendRelationship}`;
94+
} else if (mode === "topic" && topicData) {
95+
return topicData.description;
96+
}
97+
return "";
98+
};
99+
100+
const getButtonText = () => {
101+
return mode === "friend" ? "바로 대화하기" : "오픈채팅 입장하기";
37102
};
38103

39104
return (
40105
<div className="relative h-[192px] w-[157px] overflow-hidden rounded-[8px] border border-[#EEEEEE] bg-white lg:w-[200px]">
41-
<button onClick={handleDelete}>
42-
<img
43-
src="/icon/dustbin.svg"
44-
alt="Delete"
45-
className="absolute top-3 right-3 h-5 w-5 cursor-pointer"
46-
width={16}
47-
height={16}
48-
/>
49-
</button>
106+
{mode === "friend" && (
107+
<button onClick={handleDelete}>
108+
<img
109+
src="/public/icon/dustbin.svg"
110+
alt="Delete"
111+
className="absolute top-3 right-3 h-5 w-5 cursor-pointer"
112+
width={16}
113+
height={16}
114+
/>
115+
</button>
116+
)}
50117
<img
51-
src={`/image/${info.mbti}_profile.png`}
118+
src={getImageSrc()}
52119
alt="Profile"
53120
className="absolute top-[12px] left-[11px] h-12 w-12 rounded-full object-cover"
54121
/>
55122

56123
<div className="px-4 pt-[69px]">
57124
<h2 className="flex items-center space-x-1 text-base">
58-
<span className="font-bold">{info.virtualFriendName}</span>
59-
<span className="font-light text-gray-600">{info.mbti}</span>
125+
<span className="font-bold">{getTitle()}</span>
126+
{getSubtitle() && (
127+
<span className="font-light text-gray-600">{getSubtitle()}</span>
128+
)}
60129
</h2>
61-
<p className="mt-2 text-xs font-light text-gray-600">
62-
{info.virtualFriendAge} · {info.virtualFriendSex} ·{" "}
63-
{info.virtualFriendRelationship}
130+
<p className="mt-2 text-sm font-normal text-gray-600">
131+
{getDescription()}
64132
</p>
65133
</div>
66134
<button
67135
className="absolute bottom-0 h-[41px] w-full bg-primary-pale py-2 text-sm font-bold text-primary-normal"
68136
onClick={handleNavigate}
69137
>
70-
바로 대화하기
138+
{getButtonText()}
71139
</button>
72140
</div>
73141
);

src/components/ProfileContainer.tsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ const ProfileContainer = ({
1515
{list.map((el, index) => (
1616
<Profile
1717
key={index}
18+
mode="friend"
1819
info={el}
1920
deleteIndex={index}
2021
setVirtualFriendList={setVirtualFriendList}

src/components/SubTitle.tsx

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,11 @@ import trackClickEvent from "@/utils/trackClickEvent";
44
import ActionConfirmModal from "@/components/modal/ActionConfirmModal";
55
import useAuthStore from "@/store/useAuthStore";
66

7-
const SubTitle = ({ mode }: { mode: "빠른대화" | "친구목록" }) => {
7+
const SubTitle = ({
8+
mode
9+
}: {
10+
mode: "빠른대화" | "친구목록" | "주제별대화방";
11+
}) => {
812
const [needLoginModalIsOpen, setNeedLoginModalIsOpen] = useState(false);
913
const { isLoggedIn } = useAuthStore();
1014
const navigate = useNavigate();
@@ -17,6 +21,10 @@ const SubTitle = ({ mode }: { mode: "빠른대화" | "친구목록" }) => {
1721
친구목록: {
1822
title: "친구 목록",
1923
description: "친구 정보와 대화 내용을 저장해요."
24+
},
25+
주제별대화방: {
26+
title: "주제별 대화방",
27+
description: "관심 있는 주제로 대화해보세요"
2028
}
2129
};
2230

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
import Profile from "@/components/Profile";
2+
3+
type TopicData = {
4+
chatTitle: string;
5+
description: string;
6+
};
7+
8+
const topicData: TopicData[] = [
9+
{
10+
chatTitle: "T의 대화",
11+
description: "mbti t인사람들 모임"
12+
},
13+
{
14+
chatTitle: "F의 대화",
15+
description: "mbti f인사람들 모임"
16+
}
17+
];
18+
19+
const TopicProfileContainer = () => {
20+
return (
21+
<div className="grid grid-cols-2 gap-7">
22+
{topicData.map((topic, index) => (
23+
<Profile key={index} mode="topic" topicData={topic} />
24+
))}
25+
</div>
26+
);
27+
};
28+
29+
export default TopicProfileContainer;

src/pages/Home.tsx

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@ import Header from "@/components/header/Header";
1111
import useAuthStore from "@/store/useAuthStore";
1212
import ProfileContainer from "@/components/ProfileContainer";
1313
import { Helmet } from "react-helmet";
14+
import TopicProfileContainer from "@/components/TopicProfileContainer";
1415

1516
const Home = () => {
1617
const navigate = useNavigate();
@@ -47,6 +48,7 @@ const Home = () => {
4748
<section aria-label="콘텐츠 배너">
4849
<Banner />
4950
</section>
51+
5052
<section className="mt-5" aria-label="빠른 대화">
5153
<div className="w-full px-[20px] py-[13px]">
5254
<SubTitle mode="빠른대화" />
@@ -55,11 +57,21 @@ const Home = () => {
5557
<ChatStartButton mode={"go-fast"} />
5658
</div>
5759
</section>
60+
61+
<section aria-label="주제별 대화방">
62+
<div className="w-full px-[20px] py-[21px]">
63+
<SubTitle mode="주제별대화방" />
64+
</div>
65+
<div className="flex justify-center pb-[11.35px]">
66+
<TopicProfileContainer />
67+
</div>
68+
</section>
69+
5870
<section aria-label="친구 목록">
5971
<div className="px-[20px] py-[21px]">
6072
<SubTitle mode="친구목록" />
6173
</div>
62-
<div className="flex justify-center pb-[127px]">
74+
<div className="flex justify-center pb-[12px]">
6375
{isLoggedIn && virtualFreindList.length > 0 ? (
6476
<ProfileContainer
6577
list={virtualFreindList}

0 commit comments

Comments
 (0)