-
Notifications
You must be signed in to change notification settings - Fork 0
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
[#131] 대회 종료시 대시보드로 이동 기능 #150
The head ref may contain hidden characters: "131-\uB300\uD68C-\uC885\uB8CC\uC2DC-\uB300\uC2DC\uBCF4\uB4DC\uB85C-\uC774\uB3D9-\uAE30\uB2A5"
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,35 @@ | ||
import { css } from '@style/css'; | ||
|
||
import { useEffect } from 'react'; | ||
|
||
import Loading from '@/components/Common/Loading'; | ||
import useTimer from '@/hooks/timer/useTimer'; | ||
import useSocketTimer from '@/hooks/timer/useSocketTimer'; | ||
import { formatMilliSecond } from '@/utils/date'; | ||
import type { Socket } from '@/utils/socket'; | ||
|
||
interface Props { | ||
socket: Socket; | ||
isConnected: boolean; | ||
endsAt: Date; | ||
isConnected?: boolean; | ||
onTimeout?: () => void; | ||
} | ||
|
||
export default function Timer(props: Props) { | ||
let { socket, endsAt, isConnected } = props; | ||
export default function SocketTimer(props: Props) { | ||
let { socket, endsAt, isConnected, onTimeout } = props; | ||
// api 연결이 X endsAt 대신 임시로 만들어놓은 것. | ||
endsAt = new Date('2023-11-29T13:10:10.000Z'); | ||
const { remainMiliSeconds } = useTimer({ socket, endsAt }); | ||
// min 1 => 60초 동안 돌아갑니다. 변경해서 쓰세요 일단은.. | ||
const min = 120; | ||
endsAt = new Date(new Date().getTime() + min * 60 * 1000); | ||
|
||
const { remainMiliSeconds, isTimeout } = useSocketTimer({ | ||
socket, | ||
endsAt, | ||
socketEvent: 'ping', | ||
}); | ||
|
||
useEffect(() => { | ||
if (isTimeout && typeof onTimeout === 'function') onTimeout(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 여담인데 isFunction 같은 유틸을 하나 만들어야겠네요. 제쪽에서 할게요 |
||
}, [isTimeout]); | ||
|
||
if (isConnected && remainMiliSeconds !== -1) { | ||
// 연결도 되어있고, 서버 시간도 도착해서 count down을 시작할 수 있을 때 | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,6 +2,7 @@ import { css } from '@style/css'; | |
|
||
import { useContext, useEffect, useMemo, useState } from 'react'; | ||
import { useParams } from 'react-router-dom'; | ||
import { useNavigate } from 'react-router-dom'; | ||
|
||
import { ModalContext } from '@/components/Common/Modal/ModalContext'; | ||
import CompetitionHeader from '@/components/Contest/CompetitionHeader'; | ||
|
@@ -10,8 +11,8 @@ import Editor from '@/components/Editor/Editor'; | |
import ProblemViewer from '@/components/Problem/ProblemViewer'; | ||
import { SimulationInputModal } from '@/components/Simulation/SimulationInputModal'; | ||
import { SimulationResultList } from '@/components/Simulation/SimulationResultList'; | ||
import SocketTimer from '@/components/SocketTimer'; | ||
import { SubmissionResult } from '@/components/Submission'; | ||
import Timer from '@/components/Timer'; | ||
import { SITE } from '@/constants'; | ||
import type { SubmissionForm } from '@/hooks/competition'; | ||
import { useCompetition } from '@/hooks/competition'; | ||
|
@@ -22,13 +23,16 @@ import { isNil } from '@/utils/type'; | |
|
||
const RUN_SIMULATION = '테스트 실행'; | ||
const CANCEL_SIMULATION = '실행 취소'; | ||
const DASHBOARD_URL = '/contest/dashboard'; | ||
|
||
export default function ContestPage() { | ||
const { id } = useParams<{ id: string }>(); | ||
const competitionId: number = id ? parseInt(id, 10) : -1; | ||
const [currentProblemIndex, setCurrentProblemIndex] = useState(0); | ||
const modal = useContext(ModalContext); | ||
|
||
const navigate = useNavigate(); | ||
|
||
const simulation = useSimulation(); | ||
|
||
const { socket, competition, submitSolution, isConnected } = useCompetition(competitionId); | ||
|
@@ -82,22 +86,29 @@ export default function ContestPage() { | |
submitSolution(form); | ||
} | ||
|
||
|
||
const { endsAt } = competition; | ||
|
||
function handleOpenModal() { | ||
modal.open(); | ||
} | ||
|
||
|
||
function handleTimeout() { | ||
navigate(`${DASHBOARD_URL}/${competitionId}`); | ||
} | ||
|
||
const problems = problemList.map((problem) => problem.id); | ||
|
||
|
||
return ( | ||
<main className={style}> | ||
<CompetitionHeader crumbs={crumbs} id={competitionId} /> | ||
<section> | ||
<section className={rowStyle}> | ||
<span className={problemTitleStyle}>{problem.title}</span> | ||
<Timer socket={socket.current} isConnected={isConnected} endsAt={new Date(endsAt)} /> | ||
<SocketTimer | ||
socket={socket.current} | ||
isConnected={isConnected} | ||
endsAt={new Date(endsAt)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 이런 식으로 new Date를 안에 작성해줄 수 있군요:D There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 넵 endsAt가 스웨거에선 string으로 오더라구요. 바뀔수도 있겠지만 string으로 온다고 생각해서 Date로 변경해서 사용하고 있습니다. |
||
onTimeout={handleTimeout} | ||
/> | ||
</section> | ||
<section className={rowListStyle}> | ||
<ContestProblemSelector | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
2시간을 본다고 가정하는거죠?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
네 정확합니다. 직접 데이터 받아오니 끝나는 시간이 항상 지금보다 전이라 대시보드로 바로 이동해서 개발용으로 열어뒀습니다.