Skip to content
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
18 changes: 13 additions & 5 deletions src/components/Board.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -527,6 +527,7 @@ export default function Board(props) {

const getTimerDiff = () => new Date(props.timer).getTime() - new Date().getTime()
const [remainingMilliseconds, setRemainingMilliseconds] = useState( getTimerDiff() )
const [flash, setFlash] = useState(false)

const mmss = () => {
return [
Expand All @@ -538,23 +539,30 @@ export default function Board(props) {
useEffect( () => {
// If board time remaining is positive, init remaining state and interval countdown
const diff = getTimerDiff()
// console.log("DIFF", diff)
if(diff < 0) return
setRemainingMilliseconds(diff)

// setRemainingSeconds()
const countdownInterval = setInterval( () => {
const diff = getTimerDiff()
if(diff < 0) { clearInterval(countdownInterval) }
// console.log("REMAINING", diff)
setRemainingMilliseconds(diff)
}, 1000)

return () => clearInterval(countdownInterval)
}, [])

useEffect(() => {
if(getTimerDiff() > 0) {
setFlash(true)
const t = setTimeout(() => setFlash(false), 1000)
return () => clearTimeout(t)
}
}, [props.timer])

const warning = remainingMilliseconds <= 10000 && remainingMilliseconds >= 1000

return (
<div>
<div className={`${flash ? 'animate-flash-green' : ''} ${warning ? 'bg-red-200' : ''}`}>
{/* {props.timer} */}
{remainingMilliseconds > 0 ? (
<div className="flex gap-2 justify-center items-center">
Expand Down
9 changes: 9 additions & 0 deletions tailwind.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,15 @@ export default {
fontFamily: {
sans: ['Inter', 'sans-serif'],
},
keyframes: {
'flash-green': {
'0%': { backgroundColor: '#4ade80' },
'100%': { backgroundColor: 'transparent' },
},
},
animation: {
'flash-green': 'flash-green 1s ease-out',
},
},
},
plugins: [],
Expand Down