Skip to content

Commit 2c07bf6

Browse files
committed
[#50] 경매 남은 시간 표시 및 경매 아이템 상태 태그 변경
1 parent d1aabd1 commit 2c07bf6

File tree

3 files changed

+47
-2
lines changed

3 files changed

+47
-2
lines changed

src/components/MyPage/Card/CardItem.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -124,7 +124,7 @@ function Card({ post, isLike }) {
124124
) : (
125125
<RiHeartLine onClick={onClickLike} />
126126
)}
127-
<Status>판매중</Status>
127+
<Status>{post.auction === 'READY' ? '경매전' : post.auction === 'START' ? '경매중' : '경매완료'}</Status>
128128
</CardRight>
129129
</CardDetail>
130130
</CardContainer>

src/components/Nfting/index.js

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ import {
1010
} from 'reducers/auction';
1111
import useInterval from 'hooks/useInterval';
1212
import { Nfting, Images, Detail, Border } from './styles';
13+
import Timer from './timer';
1314

1415
function auctionNft({ props, status }) {
1516
const userInfo = JSON.parse(localStorage.getItem('userInfo'));
@@ -172,7 +173,11 @@ function auctionNft({ props, status }) {
172173

173174
<Border>
174175
<h3>⏱ 남은 경매시간</h3>
175-
<p>19:05:19</p>
176+
{status === 'START' ? (
177+
<Timer endDate={props.curStatus?.time} status={status} />
178+
) : (
179+
<p />
180+
)}
176181
</Border>
177182

178183
<Border>

src/components/Nfting/timer.js

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
import React, { useState } from 'react';
2+
import useInterval from 'hooks/useInterval';
3+
4+
const Timer = ({ endDate }) => {
5+
console.log(endDate);
6+
const [dateTime, setDateTime] = useState('00:00:60');
7+
8+
const getTime = () => {
9+
const endDay = new Date(endDate);
10+
const currDay = new Date();
11+
12+
let diff = endDay - currDay;
13+
const diffDays = Math.floor(
14+
(endDay.getTime() - currDay.getTime()) / (1000 * 60 * 60 * 24),
15+
);
16+
diff -= diffDays * (1000 * 60 * 60 * 24);
17+
const diffHours = Math.floor(diff / (1000 * 60 * 60));
18+
diff -= diffHours * (1000 * 60 * 60);
19+
const diffMin = Math.floor(diff / (1000 * 60));
20+
diff -= diffMin * (1000 * 60);
21+
const diffSec = Math.floor(diff / 1000);
22+
23+
const hours = diffHours < 10 ? `0${diffHours}` : diffHours;
24+
const miniutes = diffMin < 10 ? `0${diffMin}` : diffMin;
25+
const seconds = diffSec < 10 ? `0${diffSec}` : diffSec;
26+
27+
return `${hours}:${miniutes}:${seconds}`;
28+
};
29+
30+
useInterval(
31+
() => {
32+
setDateTime(getTime());
33+
},
34+
dateTime === '00:00:00' ? null : 1000,
35+
);
36+
37+
return <p>{dateTime}</p>;
38+
};
39+
40+
export default Timer;

0 commit comments

Comments
 (0)