Skip to content
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

Open
wants to merge 1 commit into
base: dev
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
109 changes: 109 additions & 0 deletions client/src/components/CountdownTimer.tsx
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 = () => {
Copy link
Member

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

const [timeLeft, setTimeLeft] = useState<number>(60);
const [isActive, setIsActive] = useState<boolean>(false);
const intervalRef = useRef<number | null>(null);
Comment on lines +4 to +6
Copy link
Member

@cristim67 cristim67 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are currently managing two states: timeLeft and isActive. Consider if you could combine these into a single state object to reduce unnecessary re-renders, as each setState call triggers a re-render.

Comment on lines +4 to +6
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to const intervalRef = useRef<ReturnType<typeof setInterval> | null>(null);


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;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Add more checkpoints like this through the process:
One for 45 seconds, one for 30 and one for 20s
Choose the colors so that they convert from blue to red
Also try to ease in into the transition


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',
Copy link
Member

Choose a reason for hiding this comment

The 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%',
Copy link
Member

@cristim67 cristim67 Sep 23, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

change this to:

const progressBarStyle: React.CSSProperties = {
  width: `${(timeLeft / 60) * 100}%`,
  // ...
};

height: '40px',
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The 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
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider adding aria-label or aria-live attributes

Comment on lines +89 to +103
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

please refactor with TailwindCss

</div>
</div>
);
};

export default CountdownTimer;
8 changes: 6 additions & 2 deletions client/src/views/QuickRound.tsx
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>
</>
);
}
}