diff --git a/components/WinnersSection.tsx b/components/WinnersSection.tsx new file mode 100644 index 0000000..22e9d76 --- /dev/null +++ b/components/WinnersSection.tsx @@ -0,0 +1,108 @@ +"use client"; + +import { useMemo } from "react"; +import { FaTrophy, FaHistory } from "react-icons/fa"; + +export interface Winner { + name: string; + challengeTitle: string; + projectTitle: string; + deadline: Date; + placement: number; +} + +const monthNames = ["January", "February", "March", "April", "May", "June", "July", "August", "September", "October", "November", "December"]; + +export default function WinnersSection({ winners }: { winners: Winner[] }) { + const mostRecentDate = useMemo(() => { + let mostRecentDateNow = new Date(0); + + for (const winner of winners) + if (winner.deadline > mostRecentDateNow) + mostRecentDateNow = winner.deadline; + return mostRecentDateNow; + + }, [winners]); + + const recentWinners = useMemo(() => { + return winners.filter((winner) => winner.deadline >= mostRecentDate); + }, [winners, mostRecentDate]); + + const prevWinners = useMemo(() => { + return winners.filter((winner) => winner.deadline < mostRecentDate); + }, [winners, mostRecentDate]); + + return ( +
+

+ {monthNames[mostRecentDate.getMonth()]}'s Winners +

+ +
+ {recentWinners.map((winner) => + + )} +
+ +
+

+ + Previous Winners: +

+
+ {prevWinners.map((winner) => + + )} +
+
+ +
+ ); +} + +function WinnerCard({ placement, name, projectTitle }: Winner) { + const placementColors = ["text-gold", "text-slate-400", "text-orange-800"]; + const placementColor = placement > 3 ? "" : placementColors[placement - 1]; + + // regex setup for initials + const clean = name.replace(/( |_|-|\/|\\|#|\.)/g, " "); // remove common name seperators + const match = clean.match(/([a-z A-Z])\w+\s([a-z A-Z])\w*\s*([a-z A-Z])*(?=,*)/); // find and place initials in array + + // if match exists, it MUST have at least 3 elements in array + // 0 index of match is original string + const initials = ((match) ? match[1] + match[2] : name.charAt(0)).toUpperCase(); + + return ( +
+
+ + #{placement} +
+ +
+
+ {initials} +
+
+ {name} +
+
+ {projectTitle} +
+
+
+ ); +} + +function PrevWinnerEntry({ name, challengeTitle, deadline }: Winner) { + return ( +
+

{monthNames[deadline.getMonth()]} {deadline.getFullYear()}

+

{name}

+

{challengeTitle}

+
+ ); +}