-
Notifications
You must be signed in to change notification settings - Fork 1
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: fable test app homepage #39
Changes from 2 commits
e0afd11
322deb5
44305fa
345ca4f
13f3c85
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,19 +1,25 @@ | ||||||
import React from 'react'; | ||||||
import { Text } from '../components'; | ||||||
import { Text, Heading } from '../components'; | ||||||
|
||||||
import { Provinces } from '../utils/constants'; | ||||||
|
||||||
interface NextHolidayProps { | ||||||
display?: 'banner' | 'table'; | ||||||
display?: 'banner' | 'table' | 'homepage'; | ||||||
isCurrentHoliday? : boolean; | ||||||
nextHoliday: { | ||||||
date: string; | ||||||
nameEn: string; | ||||||
} | null; | ||||||
federal?: boolean; | ||||||
observedIn?: Provinces[]; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I like this one better for clarity, what do you think?
Suggested change
|
||||||
} | ||||||
|
||||||
const NextHoliday: React.FC<NextHolidayProps> = ({ | ||||||
display = 'banner', | ||||||
isCurrentHoliday = false, | ||||||
nextHoliday | ||||||
nextHoliday, | ||||||
federal, | ||||||
observedIn | ||||||
}) => { | ||||||
// Calculate days until the next holiday | ||||||
const calcNextHoliday = (dateString: string) => { | ||||||
|
@@ -23,6 +29,27 @@ const NextHoliday: React.FC<NextHolidayProps> = ({ | |||||
return Math.floor((holidayDate.getTime() - today.getTime()) / (1000 * 3600 * 24)); | ||||||
}; | ||||||
|
||||||
// Get long version of date | ||||||
const nextHolidayDate = (dateString: string) => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I see potential for this to be generalized, especially seeing the function call is
Suggested change
|
||||||
const holidayDate = new Date(dateString); | ||||||
|
||||||
return `${holidayDate.toLocaleString('default', { month: 'long' })} ${holidayDate.getDate()}`; | ||||||
}; | ||||||
|
||||||
// Create formatted list of <abbr> elements for provinces | ||||||
const formatObservedIn = () => { | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
or something similar; |
||||||
if (observedIn) { | ||||||
if (observedIn.length === 1) { | ||||||
return <abbr title={observedIn[0].nameEn}>{observedIn[0].id}</abbr>; | ||||||
} else { | ||||||
return observedIn.map((value, i: number) => <span key={i}> | ||||||
{i === observedIn.length - 1 && " and "} | ||||||
<abbr title={value.nameEn}>{value.id}</abbr>{i != observedIn.length - 1 ? ", " : "."} | ||||||
</span>); | ||||||
} | ||||||
} | ||||||
}; | ||||||
|
||||||
const daysToNextHoliday = nextHoliday ? calcNextHoliday(nextHoliday.date) : null; | ||||||
|
||||||
if (!nextHoliday) { | ||||||
|
@@ -46,6 +73,43 @@ const NextHoliday: React.FC<NextHolidayProps> = ({ | |||||
src="/icons/icon-calendar.svg" | ||||||
alt="Calendar icon with a clock in the bottom right corner." | ||||||
/> | ||||||
) : display ==='homepage' ? ( | ||||||
<section className={`pt-700 pb-700 mb-300 next-holiday-homepage ${federal ? `img-federal` : 'img-nonfederal'}`}> | ||||||
<div className="bg-light md:px-450 px-250 d-block pt-100 pb-500"> | ||||||
<Heading tag="h2"> | ||||||
{federal ? | ||||||
<span className="font-secondary">Next federal statutory holiday</span> | ||||||
: | ||||||
<span className="font-secondary">Next non-federal statutory holiday</span> | ||||||
} | ||||||
</Heading> | ||||||
<strong className="d-block mb-100 font-h4"> | ||||||
{nextHoliday.nameEn} | ||||||
</strong> | ||||||
<div className="font-h5 font-medium"> | ||||||
<time> | ||||||
{nextHolidayDate(nextHoliday.date)} | ||||||
</time> | ||||||
{!federal ? | ||||||
<p className="d-inline font-h5 font-medium"> | ||||||
- Observed in {formatObservedIn()} | ||||||
</p> | ||||||
: | ||||||
null | ||||||
} | ||||||
</div> | ||||||
</div> | ||||||
<div className="d-flex bg-primary md:align-items-center align-items-center text-light md:px-450 px-250 py-200"> | ||||||
<Text textRole="light" marginBottom="0"> | ||||||
<strong>That's in {daysToNextHoliday} days!</strong> | ||||||
</Text> | ||||||
<img | ||||||
className="d-inline-block ms-400" | ||||||
src="/icons/icon-calendar.svg" | ||||||
alt="Calendar icon with a clock in the bottom right corner." | ||||||
/> | ||||||
</div> | ||||||
</section> | ||||||
) : null; | ||||||
}; | ||||||
|
||||||
|
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -1,16 +1,74 @@ | ||||||
import React from 'react'; | ||||||
import React, { useEffect, useState } from 'react'; | ||||||
import axios from 'axios'; | ||||||
|
||||||
// Components (internal) | ||||||
import { DateModified, Heading, Text } from '../components'; | ||||||
import { DateModified, Heading, NextHoliday, Text, Button } from '../components'; | ||||||
import { holidayObject } from '../utils/constants'; | ||||||
|
||||||
const Home: React.FC = () => { | ||||||
const currentDate = new Date().getTime(); | ||||||
const [nextFederal, setNextFederal] = useState<holidayObject>(); | ||||||
const [nextNationwide, setNextNationwide] = useState<holidayObject>(); | ||||||
|
||||||
useEffect(() => { | ||||||
axios.get('https://canada-holidays.ca/api/v1/holidays') | ||||||
.then(({ data }) => { | ||||||
|
||||||
// Assign next federal holiday | ||||||
let fedAssigned = false; | ||||||
data.holidays.map((holiday: holidayObject) => { | ||||||
if (holiday.federal === 1) { | ||||||
const holidayDate = new Date (holiday.date).getTime(); | ||||||
daine marked this conversation as resolved.
Show resolved
Hide resolved
|
||||||
if (holidayDate > currentDate && !fedAssigned) { | ||||||
fedAssigned = true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Small suggestion to do the boolean check first so it doesn't have to do the second check if it's already been assigned
Suggested change
|
||||||
setNextFederal(holiday); | ||||||
} | ||||||
} | ||||||
}); | ||||||
|
||||||
// Assign next nationwide holiday | ||||||
let nationwideAssigned = false; | ||||||
data.holidays.map((holiday: holidayObject) => { | ||||||
const holidayDate = new Date (holiday.date).getTime(); | ||||||
if (holidayDate > currentDate && !nationwideAssigned) { | ||||||
nationwideAssigned = true; | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Same comment as above :) |
||||||
setNextNationwide(holiday); | ||||||
} | ||||||
}); | ||||||
}) | ||||||
.catch(error => { | ||||||
console.error("There was an error fetching the holidays!", error); | ||||||
}); | ||||||
}, []); | ||||||
|
||||||
return ( | ||||||
<section> | ||||||
<Heading tag="h1">Canada holidays</Heading> | ||||||
<Text> | ||||||
This app shows all Canadian holidays and uses GC Design System. | ||||||
</Text> | ||||||
|
||||||
<Button | ||||||
buttonRole="primary" | ||||||
type="link" | ||||||
href="/view-holidays/nationwide" | ||||||
className="mb-500" | ||||||
> | ||||||
View all holidays | ||||||
</Button> | ||||||
|
||||||
<NextHoliday | ||||||
display='homepage' | ||||||
nextHoliday={{ date: nextFederal?.date as string, nameEn: nextFederal?.nameEn as string }} | ||||||
federal | ||||||
/> | ||||||
|
||||||
<NextHoliday | ||||||
display="homepage" | ||||||
nextHoliday={{ date: nextNationwide?.date as string, nameEn: nextNationwide?.nameEn as string }} | ||||||
observedIn={nextNationwide?.provinces} | ||||||
/> | ||||||
|
||||||
<DateModified>2024-08-28</DateModified> | ||||||
</section> | ||||||
) | ||||||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could use another version bump 😜