Skip to content

Commit 2c529da

Browse files
authored
Merge pull request #250 from Ureca-Mini-Project-Team4/feature/final-2
REFACT: Poll candidate 수정
2 parents df485fb + 55b3b7e commit 2c529da

File tree

3 files changed

+31
-10
lines changed

3 files changed

+31
-10
lines changed

react-app/src/pages/Main.tsx

Lines changed: 29 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,28 @@
11
import Button from '@/components/Button/Button';
22
import FloatingBackground from '@/components/FloatingBackground/FloatingBackground';
3-
import { useCallback, useEffect, useState } from 'react';
3+
import { useCallback, useEffect, useRef, useState } from 'react';
44
import { useNavigate } from 'react-router-dom';
5-
import { formatMillisecondsToHMS, getTodayAtHour } from '@/utils/time';
65

76
const Main = () => {
87
const [restTime, setRestTime] = useState(10);
8+
9+
const nowTime = useRef(Date.now());
10+
const eightTime = new Date();
11+
eightTime.setHours(8, 0, 0, 0);
12+
913
const isVoted = localStorage.getItem('voted') === 'true';
1014

15+
const changeDateTime = useCallback((diff: number) => {
16+
const hours = Math.floor(diff / (1000 * 60 * 60));
17+
const minutes = Math.floor((diff % (1000 * 60 * 60)) / (1000 * 60));
18+
const seconds = Math.floor((diff % (1000 * 60)) / 1000);
19+
20+
return `${String(hours).padStart(2, '0')}:${String(minutes).padStart(2, '0')}:${String(seconds).padStart(2, '0')}`;
21+
}, []);
22+
1123
useEffect(() => {
12-
const todayAtFour = getTodayAtHour(16); // 16시
24+
const todayAtFour = new Date();
25+
todayAtFour.setHours(16, 0, 0, 0); // 16시
1326

1427
const updateTimer = () => {
1528
const now = new Date().getTime();
@@ -39,30 +52,38 @@ const Main = () => {
3952
<FloatingBackground />
4053
<div className="flex flex-col justify-center gap-6">
4154
<p className="text-base sm:text-lg md:text-xl text-gray-600 font-pb">
42-
{restTime > 0 ? '투표 결과 발표까지 남은 시간' : '투표 집계가 완료되었습니다.'}
55+
{nowTime.current > eightTime.getTime() && restTime > 0
56+
? '투표 결과 발표까지 남은 시간'
57+
: '투표 집계가 완료되었습니다.'}
4358
</p>
4459
<p
4560
className={`${
46-
restTime > 0
61+
nowTime.current > eightTime.getTime() && restTime > 0
4762
? 'text-gray-600'
4863
: 'bg-gradient-to-r from-red-500 to-lime-300 bg-clip-text text-transparent'
4964
} text-3xl sm:text-4xl md:text-5xl font-pb`}
5065
>
51-
{restTime > 0 ? formatMillisecondsToHMS(restTime) : '결과 발표'}
66+
{nowTime.current > eightTime.getTime() && restTime > 0
67+
? changeDateTime(restTime)
68+
: '결과 발표'}
5269
</p>
5370
<p className="mt-4 text-3xl sm:text-5xl md:text-6xl font-pb leading-none">
5471
<span className="bg-[var(--color-primary-base)] px-2">너로</span> 정했다!
5572
</p>
5673
</div>
5774
<div className="w-full max-w-xs text-base sm:text-lg md:text-xl font-pb mt-10">
58-
{restTime > 0 ? (
75+
{nowTime.current > eightTime.getTime() && restTime > 0 ? (
5976
<Button
6077
onClick={handleMoveToVote}
6178
label={isVoted ? '투표완료' : '투표하기'}
6279
disabled={isVoted}
6380
/>
6481
) : (
65-
<Button onClick={handleMoveToResult} label="결과 확인" />
82+
<Button
83+
onClick={handleMoveToResult}
84+
label="결과 확인"
85+
disabled={nowTime.current - eightTime.getTime() > 0 ? true : false}
86+
/>
6687
)}
6788
</div>
6889
</div>

springboot-app/src/main/java/com/uplus/eureka/candidate/scheduler/CandidateScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public CandidateScheduler(CandidateController candidateController) {
1313
this.candidateController = candidateController;
1414
}
1515

16-
@Scheduled(cron = "0 01 14 * * ?", zone = "Asia/Seoul")
16+
@Scheduled(cron = "0 59 07 * * ?", zone = "Asia/Seoul")
1717
public void runCreateCandidates() {
1818
candidateController.createCandidates();
1919
}

springboot-app/src/main/java/com/uplus/eureka/poll/scheduler/PollScheduler.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ public PollScheduler(PollController pollController) {
1313
this.pollController = pollController;
1414
}
1515

16-
@Scheduled(cron = "0 00 14 * * ?", zone = "Asia/Seoul")
16+
@Scheduled(cron = "0 58 07 * * ?", zone = "Asia/Seoul")
1717
public void runPutQuestions() {
1818
pollController.getRandomQuestions();
1919
}

0 commit comments

Comments
 (0)