Skip to content

Commit ab49a16

Browse files
committed
connect past winners to contentful
1 parent 9929707 commit ab49a16

File tree

3 files changed

+38
-74
lines changed

3 files changed

+38
-74
lines changed

src/app/contentfulTypes.ts

+12
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@ export interface ContentTypeMap {
4444
timeline: BaseEntry;
4545
upcomingEvents: BaseEntry;
4646
ceremonyDetails: CeremonyDetails;
47+
pastHackathonWinner: PastHackathonWinner;
4748
// add more types as needed...
4849
}
4950

@@ -53,3 +54,14 @@ export interface CeremonyDetails extends BaseEntry {
5354
closingCeremonyLocation: string;
5455
closingCeremonyDate: string;
5556
}
57+
58+
export interface PastHackathonWinner extends BaseEntry {
59+
projectName: string;
60+
projectDescription?: string;
61+
projectImage?: Asset;
62+
hackathonName?: string;
63+
teamName?: string;
64+
teamRanking?: number;
65+
awardName?: string;
66+
link?: string;
67+
}

src/components/LandingPage/PastWinners.tsx

+13-66
Original file line numberDiff line numberDiff line change
@@ -1,84 +1,31 @@
1+
import { fetchContent } from "@/app/actions";
2+
import type { PastHackathonWinner } from "@/app/contentfulTypes";
13
import { Underline } from "@/utils/text-utils";
24

35
import WinnerCard from "./WinnerCard";
46

5-
export type PastWinner = {
6-
name: string;
7-
description: string;
8-
image: string;
9-
team: string;
10-
rank: number;
11-
award: string;
12-
link: string;
13-
};
14-
15-
const pastWinners: PastWinner[] = [
16-
{
17-
name: "Seed-Pod",
18-
description: "A seed that grows into a pod.",
19-
image: "seed-pod.jpg",
20-
team: "Team 1",
21-
rank: 1,
22-
award: "2024 Winner",
23-
link: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s",
24-
},
25-
{
26-
name: "Seed-Pod",
27-
description: "A seed that grows into a pod.",
28-
image: "seed-pod.jpg",
29-
team: "Team 2",
30-
rank: 2,
31-
award: "2024 Runner Up",
32-
link: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s",
33-
},
34-
{
35-
award: "Best Design",
36-
name: "Seed-Pod",
37-
description: "A seed that grows into a pod.",
38-
image: "seed-pod.jpg",
39-
team: "Team Solo Mid",
40-
rank: 3,
41-
link: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s",
42-
},
43-
{
44-
award: "Best Presentation",
45-
name: "Seed-Pod",
46-
description: "A seed that grows into a pod.",
47-
image: "seed-pod.jpg",
48-
team: "Awesome team poggers",
49-
rank: 4,
50-
link: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s",
51-
},
52-
{
53-
award: "Best Impact",
54-
name: "Seed-Pod",
55-
description: "A seed that grows into a pod.",
56-
image: "seed-pod.jpg",
57-
team: "Justin's cool team",
58-
rank: 5,
59-
link: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s",
60-
},
61-
] as const;
62-
63-
export default function PastWinners() {
64-
const sortedPastWinners = pastWinners.reduce(
65-
(acc, el) => (el.rank % 2 ? [...acc, el] : [el, ...acc]),
66-
[] as PastWinner[],
67-
);
68-
7+
export default async function PastWinners() {
8+
const data = await fetchContent("pastHackathonWinner");
9+
const pastWinners = data.map((el) => el.fields);
10+
const sortedPastWinners = pastWinners
11+
.sort((a, b) => (a.teamRanking ?? 0) - (b.teamRanking ?? 0))
12+
.reduce(
13+
(acc, el, index) => (index % 2 ? [...acc, el] : [el, ...acc]),
14+
[] as PastHackathonWinner[],
15+
);
6916
return (
7017
<div className=" flex flex-col gap-2 bg-fuzzy-peach lg:p-10 ">
7118
<h1 className="text-nowrap p-4 text-2xl font-extrabold sm:w-1/4">
7219
<Underline noTick>
73-
{" Last Year's "}
20+
{" Previous Year's "}
7421
<span className="pl-1 italic text-awesomer-purple">Winners</span>
7522
</Underline>
7623
</h1>
7724
<div className="flex w-full snap-x items-center justify-center overflow-x-auto lg:overflow-visible">
7825
<ul className="flex max-h-screen w-full max-w-screen-2xl justify-around gap-2 sm:aspect-auto">
7926
{Object.entries(sortedPastWinners).map(([key, value], index) => (
8027
<WinnerCard
81-
pastWinnersArraySize={pastWinners.length}
28+
pastWinnersArraySize={sortedPastWinners.length}
8229
pastWinner={value}
8330
key={key}
8431
index={index}

src/components/LandingPage/WinnerCard.tsx

+13-8
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
import Link from "next/link";
22
import { twMerge } from "tailwind-merge";
33

4+
import type { PastHackathonWinner } from "@/app/contentfulTypes";
45
import imgPlaceholder from "@/images/imgplaceholder.png";
56

6-
import type { PastWinner } from "./PastWinners";
7-
87
const ColorCycles = [
98
"bg-orange-300",
109
"bg-awesomer-purple",
@@ -20,7 +19,7 @@ export default function WinnerCard({
2019
pastWinnersArraySize,
2120
}: {
2221
pastWinnersArraySize: number;
23-
pastWinner: PastWinner;
22+
pastWinner: PastHackathonWinner;
2423
className?: string;
2524
index: number;
2625
}) {
@@ -30,7 +29,9 @@ export default function WinnerCard({
3029
<li
3130
style={
3231
{
33-
backgroundImage: `url(${imgPlaceholder.src})`,
32+
backgroundImage: pastWinner.projectImage
33+
? `url(${pastWinner.projectImage.fields.file?.url})`
34+
: `url(${imgPlaceholder.src})`,
3435
"--tw-scale-x": scaleValue,
3536
"--tw-scale-y": scaleValue,
3637
} as React.CSSProperties
@@ -41,21 +42,25 @@ export default function WinnerCard({
4142
)}
4243
>
4344
<Link
44-
href={pastWinner.link}
45+
href={
46+
pastWinner.link
47+
? pastWinner.link
48+
: "https://www.youtube.com/watch?v=mCdA4bJAGGk&t=19s"
49+
}
4550
target="_blank"
4651
className="absolute inset-0 flex flex-col justify-end rounded-3xl bg-gradient-to-b from-black/50 via-black/0 to-black pb-4 shadow-2xl drop-shadow-2xl "
4752
>
4853
<div
4954
className={` ${ColorCycles[index % ColorCycles.length]} w-fit rounded-r-3xl px-3 py-1 text-xs font-bold tracking-wider text-white shadow-lg xl:text-xl`}
5055
>
51-
{pastWinner.award}
56+
{pastWinner.awardName}
5257
</div>
5358
<div className="px-2 text-white">
5459
<h2 className="text-lg font-bold italic drop-shadow-xl xl:text-3xl">
55-
{pastWinner.name}
60+
{pastWinner.projectName}
5661
</h2>
5762
<p className=" truncate text-sm xl:text-lg">
58-
{pastWinner.description}
63+
{pastWinner.projectDescription}
5964
</p>
6065
</div>
6166
</Link>

0 commit comments

Comments
 (0)