Skip to content

Commit

Permalink
feat: 이벤트 진행 시작될 때 자동 새로 고침
Browse files Browse the repository at this point in the history
  • Loading branch information
nim-od committed Aug 21, 2024
1 parent 336a9a2 commit eb8e9fc
Showing 1 changed file with 18 additions and 0 deletions.
18 changes: 18 additions & 0 deletions packages/user/src/pages/NotStartedEventPage.tsx
Original file line number Diff line number Diff line change
@@ -1,3 +1,4 @@
import { useEffect, useRef } from 'react';
import { useRouteError } from 'react-router-dom';
import EventTimer from 'src/components/shared/timer/index.tsx';
import useGetEventDuration from 'src/hooks/query/useGetEventDuration.ts';
Expand All @@ -6,12 +7,29 @@ import CustomError from 'src/utils/error.ts';

export default function NotStartedEventPage() {
const error = useRouteError() as CustomError;
const timerRef = useRef<ReturnType<typeof setTimeout> | null>(null);

const {
duration: { startTime },
formattedDuration,
} = useGetEventDuration();

useEffect(() => {
if (error.status === 403 && startTime) {
const current = new Date().getTime();
const start = new Date(startTime).getTime();
const timeUntilStart = start - current;

if (timeUntilStart > 0) {
timerRef.current = setTimeout(() => window.location.reload(), timeUntilStart);
}
}

return () => {
if (timerRef.current) clearTimeout(timerRef.current);
};
}, [startTime, error.status]);

if (error.status === 403) {
return (
<div
Expand Down

0 comments on commit eb8e9fc

Please sign in to comment.