-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #17 from depromeet/feat/timer-logic
타이머 기능 추가
- Loading branch information
Showing
7 changed files
with
162 additions
and
46 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,10 @@ | ||
import { type PropsWithChildren } from 'react'; | ||
import Header from '@/components/Layout/Header'; | ||
import { css } from '@/styled-system/css'; | ||
|
||
export default function Layout({ children }: PropsWithChildren) { | ||
return ( | ||
<div className={containerCss}> | ||
<Header title={'미션 타이머'} /> | ||
<main className={mainCss}>{children}</main> | ||
</div> | ||
); | ||
return <div className={containerCss}>{children}</div>; | ||
} | ||
|
||
const containerCss = css({ | ||
background: 'linear-gradient(136deg, #FFF1F2 4.76%, #E9EFFF 89.58%)', | ||
minHeight: '100vh', | ||
}); | ||
|
||
const mainCss = css({ | ||
padding: '24px 16px', | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
import { useEffect, useState } from 'react'; | ||
import { type StepType } from '@/app/timer/useTimerStatus'; | ||
|
||
export default function useTimer(status: StepType, initSeconds = 600) { | ||
const [second, setSecond] = useState(initSeconds); // 남은 시간 (단위: 초) | ||
|
||
const formattedTime = formatMMSS(second); | ||
|
||
useEffect(() => { | ||
let timer: NodeJS.Timeout; | ||
|
||
if (second <= 0) { | ||
return; | ||
} | ||
|
||
if (status === 'progress') { | ||
timer = setInterval(() => { | ||
setSecond((prev) => prev - 1); | ||
}, 1000); | ||
} | ||
return () => clearInterval(timer); | ||
}, [second, status]); | ||
|
||
return { formattedTime }; | ||
} | ||
|
||
const formatMMSS = (second: number): [string, string] => { | ||
const minutes = Math.floor(second / 60); // 분 계산 | ||
const seconds = second % 60; // 초 계산 | ||
const formattedMinutes = String(minutes).padStart(2, '0'); // 두 자리로 변환 | ||
const formattedSeconds = String(seconds).padStart(2, '0'); // 두 자리로 변환 | ||
|
||
return [formattedMinutes, formattedSeconds]; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { useState } from 'react'; | ||
|
||
export type StepType = 'ready' | 'progress' | 'stop'; | ||
|
||
const TIMER_STATUS = { | ||
ready: { | ||
title: '준비 되셨나요?', | ||
desc: '타이머를 눌러서 10분의 미션을 완성해 주세요!', | ||
}, | ||
progress: { | ||
title: '시작!', | ||
desc: '10분 동안 최선을 다해주세요!', | ||
}, | ||
stop: { | ||
title: '잠시 멈췄어요', | ||
desc: '준비가 되면 타이머를 다시 시작해주세요!', | ||
}, | ||
} as const; | ||
|
||
function useTimerStatus() { | ||
const [step, setStep] = useState<StepType>('ready'); | ||
|
||
const stepLabel = TIMER_STATUS[step]; | ||
|
||
const onNextStep = (nextStep: StepType) => { | ||
setStep(nextStep); | ||
}; | ||
|
||
return { step, onNextStep, stepLabel }; | ||
} | ||
|
||
export default useTimerStatus; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters