-
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
Branch florian #14
base: dev
Are you sure you want to change the base?
Branch florian #14
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 |
---|---|---|
@@ -0,0 +1,109 @@ | ||
import React, { useState, useEffect, useRef } from 'react'; | ||
|
||
const CountdownTimer: React.FC = () => { | ||
const [timeLeft, setTimeLeft] = useState<number>(60); | ||
const [isActive, setIsActive] = useState<boolean>(false); | ||
const intervalRef = useRef<number | null>(null); | ||
Comment on lines
+4
to
+6
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. You are currently managing two states:
Comment on lines
+4
to
+6
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. change this to |
||
|
||
useEffect(() => { | ||
if (isActive && timeLeft > 0) { | ||
intervalRef.current = window.setInterval(() => { | ||
setTimeLeft((prevTime) => prevTime - 1); | ||
}, 1000); | ||
} else if (timeLeft === 0 || !isActive) { | ||
if (intervalRef.current) { | ||
clearInterval(intervalRef.current); | ||
intervalRef.current = null; | ||
} | ||
} | ||
|
||
return () => { | ||
if (intervalRef.current) { | ||
clearInterval(intervalRef.current); | ||
} | ||
}; | ||
}, [isActive, timeLeft]); | ||
|
||
const handleStart = () => { | ||
setIsActive(true); | ||
}; | ||
|
||
const handleReset = () => { | ||
setIsActive(false); | ||
setTimeLeft(60); | ||
}; | ||
|
||
const handleStop = () => { | ||
setIsActive(false); | ||
}; | ||
|
||
const isCritical = timeLeft < 10; | ||
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. Add more checkpoints like this through the process: |
||
|
||
const containerStyle: React.CSSProperties = { | ||
display: 'flex', | ||
flexDirection: 'column', | ||
justifyContent: 'center', | ||
alignItems: 'center', | ||
height: '100vh', | ||
backgroundColor: '#E0F2FE', | ||
}; | ||
|
||
const buttonStyle: React.CSSProperties = { | ||
margin: '10px', | ||
fontSize: '1.5rem', | ||
color: '#FFFFFF', | ||
backgroundColor: isCritical ? '#C026D3' : '#1D4ED8', | ||
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. Change the color for the last second from purple to red |
||
padding: '10px 20px', | ||
border: 'none', | ||
borderRadius: '5px', | ||
cursor: 'pointer', | ||
}; | ||
|
||
const timerStyle: React.CSSProperties = { | ||
fontSize: '12rem', | ||
color: isCritical ? '#C026D3' : '#1D4ED8', | ||
fontWeight: 'bold', | ||
}; | ||
|
||
const progressBarContainerStyle: React.CSSProperties = { | ||
width: '80%', | ||
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. change this to:
|
||
height: '40px', | ||
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. It might overflow on smaller screens. Add media queries or use rem. |
||
backgroundColor: '#E5E7EB', | ||
borderRadius: '5px', | ||
marginTop: '2px', | ||
overflow: 'hidden', | ||
}; | ||
|
||
const progressBarStyle: React.CSSProperties = { | ||
width: `${(60 - timeLeft) / 60 * 100}%`, | ||
height: '100%', | ||
backgroundColor: isCritical ? '#C026D3' : '#1D4ED8', | ||
transition: 'width 1s linear', | ||
}; | ||
|
||
const buttonContainerStyle: React.CSSProperties = { | ||
marginTop: '40px', // Increased margin to move the buttons further down | ||
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. remove comments. |
||
}; | ||
|
||
return ( | ||
<div style={containerStyle}> | ||
<h1 style={timerStyle}>{timeLeft}</h1> | ||
<div style={progressBarContainerStyle}> | ||
<div style={progressBarStyle}></div> | ||
</div> | ||
<div style={buttonContainerStyle}> | ||
<button style={buttonStyle} onClick={handleStart} disabled={isActive}> | ||
Start | ||
</button> | ||
<button style={buttonStyle} onClick={handleReset}> | ||
Reset | ||
</button> | ||
<button style={buttonStyle} onClick={handleStop}> | ||
Stop | ||
</button> | ||
Comment on lines
+95
to
+103
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. Consider adding
Comment on lines
+89
to
+103
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. please refactor with TailwindCss |
||
</div> | ||
</div> | ||
); | ||
}; | ||
|
||
export default CountdownTimer; |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,11 @@ | ||
import CountdownTimer from '../components/CountdownTimer'; | ||
import React from 'react' | ||
export default function QuickRound() { | ||
return ( | ||
<> | ||
<div>QuickRound</div> | ||
<div> | ||
<CountdownTimer /> | ||
</div> | ||
</> | ||
); | ||
} | ||
} |
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.
add zero case handling: if the countdown reaches
0
as a use i like to show me something like: "Time's up!"or disabling the
Start
button