-
Notifications
You must be signed in to change notification settings - Fork 2
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
[FE] 페어룸 타이머 기능 구현 #114
Merged
Merged
[FE] 페어룸 타이머 기능 구현 #114
Changes from all commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
6729213
:lipstick: TimerCard 컴포넌트 UI 구현
anttiey f70ec25
:sparkles: 기본 타이머 동작 기능 구현
anttiey a387563
:sparkles: 타이머 시작, 일시 정지, 정지 기능 구현
anttiey 8191787
:recycle: 타이머 로직 useTimer 커스텀 훅으로 분리
anttiey 3649c8b
:bug: 타이머 시간이 제대로 줄어들지 않는 오류 해결
anttiey 5502d43
:bug: 버튼 disabled 동작이 되지 않는 오류 해결
anttiey File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
80 changes: 80 additions & 0 deletions
80
frontend/src/components/PairRoom/TimerCard/TimerCard.styles.ts
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,80 @@ | ||
import { FaPause, FaPlay, FaStop } from 'react-icons/fa6'; | ||
import styled, { css } from 'styled-components'; | ||
|
||
export const Layout = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 3rem; | ||
width: 100%; | ||
height: 100%; | ||
padding: 3rem; | ||
`; | ||
|
||
export const ProgressBar = styled.div<{ $progress: number }>` | ||
display: flex; | ||
justify-content: center; | ||
align-items: center; | ||
width: 28vw; | ||
height: 28vw; | ||
max-width: 100%; | ||
max-height: 100%; | ||
border: 0.8rem solid transparent; | ||
border-radius: 50%; | ||
background-image: linear-gradient(white, white), | ||
conic-gradient( | ||
${({ theme, $progress }) => `${theme.color.primary[500]} ${$progress}%, ${theme.color.black[30]} ${$progress}%`} | ||
); | ||
background-origin: border-box; | ||
background-clip: content-box, border-box; | ||
transition: background-image 1s ease-in; | ||
`; | ||
|
||
export const Timer = styled.div` | ||
display: flex; | ||
align-items: center; | ||
gap: 4rem; | ||
`; | ||
|
||
export const TimerTextContainer = styled.div` | ||
display: flex; | ||
flex-direction: column; | ||
justify-content: center; | ||
align-items: center; | ||
gap: 0.4rem; | ||
width: 10rem; | ||
font-size: ${({ theme }) => theme.fontSize.sm}; | ||
`; | ||
|
||
export const TimerText = styled.p` | ||
font-size: 7rem; | ||
`; | ||
|
||
export const IconContainer = styled.div` | ||
display: flex; | ||
gap: 5rem; | ||
`; | ||
|
||
export const IconButton = styled.button` | ||
width: ${({ theme }) => theme.fontSize.h4}; | ||
background: transparent; | ||
font-size: ${({ theme }) => theme.fontSize.h4}; | ||
`; | ||
|
||
const iconStyle = css<{ $isActive: boolean }>` | ||
color: ${({ $isActive, theme }) => ($isActive ? theme.color.secondary[500] : theme.color.black[50])}; | ||
cursor: ${({ $isActive }) => ($isActive ? 'pointer' : 'default')}; | ||
`; | ||
|
||
export const PlayIcon = styled(FaPlay)<{ $isActive: boolean }>` | ||
${iconStyle} | ||
`; | ||
|
||
export const PauseIcon = styled(FaPause)<{ $isActive: boolean }>` | ||
${iconStyle} | ||
`; | ||
|
||
export const StopIcon = styled(FaStop)<{ $isActive: boolean }>` | ||
${iconStyle} | ||
`; |
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 |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { useRef, useState, useEffect } from 'react'; | ||
|
||
const useTimer = (defaultTime: number) => { | ||
const timerRef = useRef<NodeJS.Timeout | null>(null); | ||
|
||
const [timeLeft, setTimeLeft] = useState(defaultTime); | ||
const [isActive, setIsActive] = useState(false); | ||
|
||
const handleStart = () => setIsActive(true); | ||
|
||
const handlePause = () => setIsActive(false); | ||
|
||
const handleStop = () => { | ||
setIsActive(false); | ||
setTimeLeft(defaultTime); | ||
}; | ||
|
||
useEffect(() => { | ||
if (isActive && timeLeft > 0) { | ||
timerRef.current = setInterval(() => { | ||
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. setInterval로 타이머 시간을 계산하면 큰 오차가 발생할 수도 있어요. |
||
setTimeLeft((timeLeft) => timeLeft - 1000); | ||
}, 1000); | ||
} | ||
|
||
if (timeLeft === 0) { | ||
setIsActive(false); | ||
setTimeLeft(defaultTime); | ||
} | ||
|
||
return () => { | ||
if (timerRef.current) clearInterval(timerRef.current); | ||
}; | ||
}, [timeLeft, isActive]); | ||
|
||
return { timeLeft, isActive, handleStart, handlePause, handleStop }; | ||
}; | ||
|
||
export default useTimer; |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
👍
다만 초 단위로 렌더링되다 보니 애니메이션이 부드럽게 작동하지는 않네요 😢
추후 리팩터링 때 밀리초 단위를 적용하면 더 부드럽게 작동할 수 있겠네요!
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.
역시 타이머 장인 👍