generated from UoaWDCC/ssr-template
-
Notifications
You must be signed in to change notification settings - Fork 0
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
Nick/feature/event home page card/99 #135
Open
nlia656
wants to merge
21
commits into
main
Choose a base branch
from
nick/feature/event-home-page-card/99
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 16 commits
Commits
Show all changes
21 commits
Select commit
Hold shift + click to select a range
c7b0386
feat: style for upcoming event slider, not linked to cms yet
nlia656 488b47b
added card for homepage upcoming events
nlia656 45da3db
Merge branch 'main' into nick/feature/event-home-page-card/99
gmat224 bc367c3
Format code with Prettier
github-actions[bot] 3d95957
used useEffect
nlia656 d939264
Merge branch 'nick/feature/event-home-page-card/99' of https://github…
nlia656 528f666
linked to cms
nlia656 02687a8
Format code with Prettier
github-actions[bot] cded2d3
moved slider
nlia656 02d351b
Merge branch 'nick/feature/event-home-page-card/99' of https://github…
nlia656 b39afc5
moved slider
nlia656 5f99658
Format code with Prettier
github-actions[bot] 386d179
events ordered by date
nlia656 0edc8ed
Merge branch 'nick/feature/event-home-page-card/99' of https://github…
nlia656 9d955b1
Format code with Prettier
github-actions[bot] 16a052e
Merge branch 'main' into nick/feature/event-home-page-card/99
nlia656 ed6c081
refsctored stuff
nlia656 2a6623d
Format code with Prettier
github-actions[bot] 6189c2b
added test case
nlia656 9fd2a83
Merge branch 'nick/feature/event-home-page-card/99' of https://github…
nlia656 d056097
Format code with Prettier
github-actions[bot] File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -17,6 +17,7 @@ | |
}, | ||
"packageManager": "[email protected]+sha512.a6b2f7906b721bba3d67d4aff083df04dad64c399707841b7acf00f6b133b7ac24255f2652fa22ae3534329dc6180534e98d17432037ff6fd140556e2bb3137e", | ||
"dependencies": { | ||
"dayjs": "^1.11.13" | ||
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. add comma here |
||
"@apollo/client": "^3.10.8" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
import { Event } from "../types/types"; | ||
|
||
interface UpcomingEventCardProps { | ||
upcomingEvent: Event; | ||
} | ||
|
||
export default function UpcomingEventHomeCard({ | ||
upcomingEvent, | ||
}: UpcomingEventCardProps) { | ||
const formattedDate = new Date( | ||
upcomingEvent.eventDateStart | ||
).toLocaleDateString("en-NZ", { | ||
day: "numeric", | ||
month: "long", | ||
}); | ||
|
||
return ( | ||
<div className="grid h-full w-72 grid-cols-2"> | ||
<div className="m-3 h-80 w-64 flex-col items-center justify-center rounded-lg py-10"> | ||
<img | ||
className="h-64 w-64 rounded-lg object-cover" | ||
src={upcomingEvent.image} | ||
alt="Event Image" | ||
/> | ||
<h3 className="mx-3 py-4 text-center text-3xl font-bold text-white"> | ||
{upcomingEvent.title} | ||
</h3> | ||
</div> | ||
<div className="flex justify-end py-7"> | ||
<div className="bg-primary-orange flex h-10 items-center justify-center whitespace-nowrap rounded-[1.5rem]"> | ||
<div className="px-3 py-2 text-xl font-bold text-white"> | ||
{formattedDate} | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,190 @@ | ||
import Slider from "react-slick"; | ||
import "slick-carousel/slick/slick.css"; | ||
import "slick-carousel/slick/slick-theme.css"; | ||
import { | ||
IoArrowBackCircleOutline, | ||
IoArrowForwardCircleOutline, | ||
} from "react-icons/io5"; | ||
import { useRef } from "react"; | ||
import LoadingSpinner from "./LoadingSpinner"; | ||
import { useQuery, gql } from "@apollo/client"; | ||
import UpcomingEventHomeCard from "./UpcomingEventHomeCard"; | ||
import { GET_EVENTS } from "../graphql/queries"; | ||
import dayjs from "dayjs"; | ||
|
||
interface EventAttributes { | ||
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. move to types.ts file and import from there |
||
Title: string; | ||
Description: string; | ||
Subtitle: string; | ||
Location: string; | ||
Location_Link: string; | ||
Event_Date_Start: string; | ||
Event_Date_End: string; | ||
Is_Live: boolean; | ||
Terms_And_Conditions: string; | ||
Event_Capacity_Remaining: number; | ||
Image: { | ||
data: { | ||
attributes: { | ||
url: string; | ||
}; | ||
}; | ||
}; | ||
} | ||
|
||
interface RawEventData { | ||
id: number; | ||
attributes: EventAttributes; | ||
} | ||
|
||
interface Event { | ||
id: number; | ||
title: string; | ||
description: string; | ||
subtitle: string; | ||
location: string; | ||
locationLink: string; | ||
eventDateStart: string; | ||
eventDateEnd: string; | ||
isLive: boolean; | ||
termsAndConditions: string; | ||
eventCapacityRemaining: number; | ||
image: string; | ||
} | ||
|
||
interface EventResponseData { | ||
events: { | ||
data: RawEventData[]; | ||
}; | ||
} | ||
|
||
class Mapper { | ||
static mapToEvents(rawData: RawEventData[]): Event[] { | ||
if (!Array.isArray(rawData)) { | ||
return []; | ||
} | ||
|
||
return rawData | ||
.map((item) => { | ||
const { id, attributes } = item; | ||
|
||
if (!attributes) { | ||
return null; | ||
} | ||
|
||
return { | ||
id, | ||
title: attributes.Title, | ||
description: attributes.Description, | ||
subtitle: attributes.Subtitle, | ||
location: attributes.Location, | ||
locationLink: attributes.Location_Link, | ||
eventDateStart: attributes.Event_Date_Start, | ||
eventDateEnd: attributes.Event_Date_End, | ||
isLive: attributes.Is_Live, | ||
termsAndConditions: attributes.Terms_And_Conditions, | ||
eventCapacityRemaining: attributes.Event_Capacity_Remaining, | ||
image: attributes.Image.data.attributes.url, | ||
} as Event; | ||
}) | ||
.filter((event): event is Event => event !== null); | ||
} | ||
} | ||
|
||
export default function UpcomingEventHomeSlider() { | ||
const sliderRef = useRef<Slider>(null); | ||
|
||
const { | ||
loading: eventsLoading, | ||
error: eventsError, | ||
data: eventsData, | ||
} = useQuery<EventResponseData>(GET_EVENTS); | ||
|
||
if (eventsLoading) { | ||
return <LoadingSpinner />; | ||
} | ||
|
||
if (eventsError) { | ||
return <div>CMS Offline</div>; | ||
} | ||
|
||
if ( | ||
!eventsData || | ||
!eventsData.events || | ||
eventsData.events.data.length === 0 | ||
) { | ||
return <div>No data available</div>; | ||
} | ||
|
||
const events = Mapper.mapToEvents(eventsData.events.data); | ||
|
||
const now = dayjs(); // current date and time | ||
const upcomingEvents = events | ||
.filter((event) => dayjs(event.eventDateStart).isAfter(now)) // only future events | ||
.sort((a, b) => dayjs(a.eventDateStart).diff(dayjs(b.eventDateStart))); // sort by start date | ||
|
||
const settings = { | ||
dots: true, | ||
infinite: false, | ||
speed: 500, | ||
slidesToShow: 3, | ||
slidesToScroll: 1, | ||
arrows: false, | ||
responsive: [ | ||
{ | ||
breakpoint: 1080, | ||
settings: { | ||
slidesToShow: 2, | ||
}, | ||
}, | ||
{ | ||
breakpoint: 800, | ||
settings: { | ||
slidesToShow: 1, | ||
}, | ||
}, | ||
], | ||
}; | ||
|
||
const next = () => { | ||
sliderRef.current?.slickNext(); | ||
}; | ||
|
||
const previous = () => { | ||
sliderRef.current?.slickPrev(); | ||
}; | ||
|
||
function SliderNoArrow() { | ||
return ( | ||
<div> | ||
<Slider ref={sliderRef} {...settings}> | ||
{upcomingEvents.map((event) => ( | ||
<div key={event.id}> | ||
<UpcomingEventHomeCard upcomingEvent={event} /> | ||
</div> | ||
))} | ||
</Slider> | ||
</div> | ||
); | ||
} | ||
|
||
return ( | ||
<div className="flex"> | ||
<div className="flex flex-grow items-center justify-center"> | ||
<IoArrowBackCircleOutline | ||
onClick={previous} | ||
className="mx-4 hidden h-16 w-16 sm:flex" | ||
/> | ||
</div> | ||
<div className="w-11/12 sm:w-[calc(100vw-14rem)]"> | ||
<SliderNoArrow /> | ||
</div> | ||
<div className="flex flex-grow items-center justify-center"> | ||
<IoArrowForwardCircleOutline | ||
onClick={next} | ||
className="mx-4 hidden h-16 w-16 sm:flex" | ||
/> | ||
</div> | ||
</div> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
change back to 5432