Skip to content

Commit 1a98fee

Browse files
authored
Merge pull request #131 from Code-the-Change-YYC/WEB-74/connect-hackathon-timeline-to-contentful
hackathon timeline fetched from contentful
2 parents 8e07306 + 78e2c65 commit 1a98fee

File tree

2 files changed

+29
-57
lines changed

2 files changed

+29
-57
lines changed

components/HackathonTimeline.jsx

Lines changed: 29 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,57 +1,73 @@
11
import Heading from './Heading';
22
import Image from 'next/image';
33
import { UnderlineTypes } from '../utils/underlineType';
4-
import { HACKATHONS } from '../data/hackathons';
4+
import React, { useState, useEffect } from 'react';
5+
import { fetchContent } from '../api/apiRoot';
56

67
const HACKATHON_TIMELINE_CONTAINER = 'flex justify-center bg-white';
78
const HACKATHON_TIMELINE_CONTENT = 'max-w-[500px] w-[80vw] md:max-w-[1100px]';
89
const HACKATHON_TIMELINE_HEADER = 'md:justify-start md:my-[60px] my-[30px] flex justify-center';
910

1011
const HACKATHON_EVENT_INFO = 'flex text-center text-xl font-bold mb-[70px] md:items-center flex-col items-center';
1112
const HACKATHON_TITLE_YEAR = 'text-5xl pb-[15px] italic md:text-4xl';
12-
const HACKATHON_IMAGE = 'object-cover w-[80vw] md:rounded-xl md:w-[450px] md:h-[250px] md:shadow-[15px_15px_0px_0px_#00D3A9]';
13+
const HACKATHON_IMAGE =
14+
'object-cover w-[80vw] md:rounded-xl md:w-[450px] md:h-[250px] md:shadow-[15px_15px_0px_0px_#00D3A9]';
1315
const HACKATHON_TEXT = 'flex-col md:w-[400px] md:mx-[40px] leading-[1] text-[20px]';
14-
const HACKATHON_TOPIC_TEXT = 'flex text-left my-[15px] text-[#FF4D6F] md:text-[#FF6B54] md:my-1 md:font-extrabold md:text-[25px]';
16+
const HACKATHON_TOPIC_TEXT =
17+
'flex text-left my-[15px] text-[#FF4D6F] md:text-[#FF6B54] md:my-1 md:font-extrabold md:text-[25px]';
1518

1619
const HackathonSection = ({ hackathon, index }) => {
1720
let sectionInfoStyling = 'md:flex-row-reverse';
1821
let sectionTextStyling = 'md:text-right';
1922
let sectionTopicStyling = 'md:text-right md:justify-end';
2023

21-
if(index % 2 == 0) {
24+
if (index % 2 == 0) {
2225
sectionInfoStyling = 'md:flex-row md:justify-start';
2326
sectionTextStyling = 'md:text-left';
2427
sectionTopicStyling = '';
25-
}
28+
}
29+
30+
const img = 'https:' + hackathon.image.fields.file.url;
2631

2732
return (
2833
<div className={`${HACKATHON_EVENT_INFO} ${sectionInfoStyling}`}>
2934
<div>
30-
<h1 className={HACKATHON_TITLE_YEAR}>
31-
{hackathon.year}
32-
</h1>
33-
<Image className={HACKATHON_IMAGE} src={hackathon.img} alt={hackathon.title} />
35+
<h1 className={HACKATHON_TITLE_YEAR}>{hackathon.year}</h1>
36+
<Image className={HACKATHON_IMAGE} src={img} alt={hackathon.title} width={450} height={250} />
3437
</div>
3538
<div className={`${HACKATHON_TEXT} ${sectionTextStyling}`}>
3639
<div className={`${HACKATHON_TOPIC_TEXT} ${sectionTopicStyling}`}>
37-
<p className='md:hidden pr-[5px]'>Topics:</p>
40+
<p className="md:hidden pr-[5px]">Topics:</p>
3841
<p>{hackathon.topic}</p>
3942
</div>
40-
<p className='font-medium md:text-[#00D3A9]'>{hackathon.blurb}</p>
43+
<p className="font-medium md:text-[#00D3A9]">{hackathon.blurb}</p>
4144
</div>
4245
</div>
4346
);
4447
};
4548

4649
const HackathonTimeline = () => {
50+
const [hackathons, setHackathons] = useState([]);
51+
52+
useEffect(() => {
53+
fetchContent('hackathon').then((data) => {
54+
const sortedHackathons = [...data].sort((a, b) => {
55+
const yearA = parseInt(a.year);
56+
const yearB = parseInt(b.year);
57+
return yearB - yearA;
58+
});
59+
setHackathons(sortedHackathons);
60+
});
61+
}, []);
62+
4763
return (
4864
<div className={HACKATHON_TIMELINE_CONTAINER}>
4965
<div className={HACKATHON_TIMELINE_CONTENT}>
5066
<div className={HACKATHON_TIMELINE_HEADER}>
5167
<Heading underlineType={UnderlineTypes.GREEN_LONG_UNDERLINE}>Hack the Change</Heading>
5268
</div>
53-
{HACKATHONS.map((hackathon, index) => (
54-
<HackathonSection hackathon={hackathon} key={index} index={index}/>
69+
{hackathons.map((hackathon, index) => (
70+
<HackathonSection hackathon={hackathon} key={index} index={index} />
5571
))}
5672
</div>
5773
</div>

data/hackathons.js

Lines changed: 0 additions & 44 deletions
This file was deleted.

0 commit comments

Comments
 (0)