Skip to content

Commit 4471aeb

Browse files
committed
refactor: 베팅 상세 정보 부분 컴포넌트로 분리
- 기존의 베팅 상세 정보 부분 코드가 너무 길어 가독성을 해치기에 컴포넌트로 분리하였습니다.
1 parent ebf00c9 commit 4471aeb

File tree

2 files changed

+52
-38
lines changed

2 files changed

+52
-38
lines changed

frontend/src/features/betting-page-admin/index.tsx

Lines changed: 13 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import { endBetRoom, refund } from "./model/api";
1313
import { useLayoutShift } from "@/shared/hooks/useLayoutShift";
1414
import { bettingRoomSchema } from "../betting-page/model/schema";
1515
import { DuckCoinIcon } from "@/shared/icons";
16+
import BettingDetails from "./ui/BettingDetails";
1617

1718
function BettingPageAdmin() {
1819
useLayoutShift();
@@ -36,11 +37,12 @@ function BettingPageAdmin() {
3637
>(null);
3738

3839
// Room Information
39-
const roomId = channel.id;
40-
const option1 = channel.options.option1;
41-
const option2 = channel.options.option2;
42-
const defaultBetAmount = channel.settings.defaultBetAmount;
43-
const timer = channel.settings.duration;
40+
const {
41+
id: roomId,
42+
title,
43+
options: { option1, option2 },
44+
settings: { defaultBetAmount, duration: timer },
45+
} = channel;
4446

4547
const socket = useSocketIO({
4648
url: "/api/betting",
@@ -202,10 +204,6 @@ function BettingPageAdmin() {
202204
}
203205
};
204206

205-
const getTotalParticipants = () => {
206-
return bettingInfo.option1.participants + bettingInfo.option2.participants;
207-
};
208-
209207
const getTotalBetAmount = () => {
210208
return bettingInfo.option1.currentBets + bettingInfo.option2.currentBets;
211209
};
@@ -270,35 +268,12 @@ function BettingPageAdmin() {
270268
<div className="flex flex-col gap-5">
271269
<BettingTimer socket={socket} bettingRoomInfo={roomInfo} />
272270
<div className="flex flex-col gap-6 p-5">
273-
<div className="bg-secondary mb-4 rounded-lg p-3 text-center shadow-inner">
274-
<h1 className="text-default-disabled text-md mb-1 font-bold">
275-
베팅 주제
276-
</h1>
277-
<h1 className="text-primary mb-1 pt-2 text-4xl font-extrabold">
278-
{channel.title}
279-
</h1>
280-
<p>
281-
{status === "active"
282-
? "투표가 진행 중입니다. 투표를 취소할 수 있습니다."
283-
: "투표가 종료되었습니다. 승부를 결정하세요!"}
284-
</p>
285-
<h1 className="text-default-disabled text-md mb-1 font-bold">
286-
베팅 정보
287-
</h1>
288-
<p>
289-
∙ 최소 베팅 금액:{" "}
290-
<span className="font-extrabold">{defaultBetAmount}</span>
291-
</p>
292-
<p>
293-
∙ 설정한 시간:{" "}
294-
<span className="font-extrabold">{timer / 60}</span>
295-
</p>
296-
<p>
297-
∙ 전체 베팅 참여자:{" "}
298-
<span className="font-extrabold">{getTotalParticipants()}</span>
299-
</p>
300-
</div>
301-
271+
<BettingDetails
272+
title={title}
273+
defaultBetAmount={defaultBetAmount}
274+
timer={timer}
275+
status={status}
276+
/>
302277
{status === "timeover" ? (
303278
<div className="flex w-full overflow-hidden rounded-xl border">
304279
<div className="relative flex w-1/2">
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
function BettingDetails({
2+
title,
3+
defaultBetAmount,
4+
timer,
5+
status,
6+
}: {
7+
title: string;
8+
defaultBetAmount: number;
9+
timer: number;
10+
status: string;
11+
}) {
12+
return (
13+
<div className="bg-secondary mb-4 rounded-lg p-3 text-center shadow-inner">
14+
<h1 className="text-default-disabled text-md mb-1 font-bold">
15+
베팅 주제
16+
</h1>
17+
<h1 className="text-primary mb-1 pt-2 text-4xl font-extrabold">
18+
{title}
19+
</h1>
20+
<p>
21+
{status === "active"
22+
? "투표가 진행 중입니다. 투표를 취소할 수 있습니다."
23+
: "투표가 종료되었습니다. 승부를 결정하세요!"}
24+
</p>
25+
<h1 className="text-default-disabled text-md mb-1 font-bold">
26+
베팅 정보
27+
</h1>
28+
<p>
29+
∙ 최소 베팅 금액:{" "}
30+
<span className="font-extrabold">{defaultBetAmount}</span>
31+
</p>
32+
<p>
33+
∙ 설정한 시간: <span className="font-extrabold">{timer / 60}</span>
34+
</p>
35+
</div>
36+
);
37+
}
38+
39+
export default BettingDetails;

0 commit comments

Comments
 (0)