Improve countdown display with hours & minutes#321
Conversation
✅ Deploy Preview for dapper-sundae-ae0873 ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
691f28f to
3ceebdc
Compare
|
Just checking on this PR? /review |
|
/review |
3 similar comments
|
/review |
|
/review |
|
/review |
|
Test comment from API |
|
/review |
🤖 AI Code Review (Requested by @tbsoc)Code Review: Improve countdown display with hours & minutesSummaryThis PR replaces a simple day-based countdown with a more granular display that shows days, hours, or minutes depending on proximity to the deadline. It extracts the logic into a new Code QualityGood:
Issues:
SecurityNo security concerns. The component only receives a Suggestions// Consider this revised implementation
import { useState, useEffect } from "react";
import {
differenceInDays,
differenceInHours,
differenceInMinutes,
differenceInSeconds,
} from "date-fns";
interface DistributionCountdownProps {
end: Date;
}
export const DistributionCountdown = ({ end }: DistributionCountdownProps) => {
const [now, setNow] = useState<Date | null>(null);
useEffect(() => {
setNow(new Date()); // Initialize on client only
const interval = setInterval(() => setNow(new Date()), 60000); // Update every minute
return () => clearInterval(interval);
}, []);
// Prevent hydration mismatch: render nothing or a placeholder until client-side
if (!now) return <span>—</span>;
const days = differenceInDays(end, now);
if (days >= 1) {
return <span>{days} {days === 1 ? "day" : "days"}</span>;
}
const hours = differenceInHours(end, now);
if (hours >= 1) {
return <span>{hours} {hours === 1 ? "hour" : "hours"}</span>;
}
const minutes = differenceInMinutes(end, now);
if (minutes >= 1) {
return <span>{minutes} {minutes === 1 ? "minute" : "minutes"}</span>;
}
return <span>less than a minute</span>;
};Key changes:
|
fb9206f to
ad1d0e6
Compare
Closes: #315