Skip to content

Commit 0222a13

Browse files
committed
refactor community-events.json into typescript, fix load button bug, add community events for 2024
1 parent 9f6c4d4 commit 0222a13

File tree

3 files changed

+335
-219
lines changed

3 files changed

+335
-219
lines changed

src/components/UpcomingEventsList.tsx

Lines changed: 5 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -5,24 +5,14 @@ import Translation from "@/components/Translation"
55

66
import { trackCustomEvent } from "@/lib/utils/matomo"
77

8-
import events from "../data/community-events.json"
8+
import CommunityEvents, { CommunityEvent } from "../data/community-events"
99

1010
import { Button } from "./Buttons"
1111
import EventCard from "./EventCard"
1212
import InfoBanner from "./InfoBanner"
1313
import InlineLink from "./Link"
1414

15-
interface ICommunityEventData {
16-
title: string
17-
to: string
18-
sponsor: string | null
19-
location: string
20-
description: string
21-
startDate: string
22-
endDate: string
23-
}
24-
25-
interface IOrderedUpcomingEventType extends ICommunityEventData {
15+
interface IOrderedUpcomingEventType extends CommunityEvent {
2616
date: string
2717
formattedDetails: string
2818
}
@@ -33,7 +23,6 @@ const UpcomingEventsList: React.FC = () => {
3323
Array<IOrderedUpcomingEventType>
3424
>([])
3525
const [maxRange, setMaxRange] = useState<number>(eventsPerLoad)
36-
const [isVisible, setIsVisible] = useState<boolean>(true)
3726

3827
// Create Date object from each YYYY-MM-DD JSON date string
3928
const dateParse = (dateString: string): Date => {
@@ -46,7 +35,7 @@ const UpcomingEventsList: React.FC = () => {
4635
}
4736

4837
useEffect(() => {
49-
const eventsList: Array<ICommunityEventData> = [...events]
38+
const eventsList: CommunityEvent[] = [...CommunityEvents]
5039
const yesterday = new Date()
5140
yesterday.setDate(yesterday.getDate() - 1)
5241

@@ -70,9 +59,7 @@ const UpcomingEventsList: React.FC = () => {
7059
event.endDate
7160
).toLocaleDateString()}`
7261

73-
const details = `${event.sponsor ? "(" + event.sponsor + ")" : ""} ${
74-
event.description
75-
}`
62+
const details = `${event.description}`
7663

7764
return {
7865
...event,
@@ -86,7 +73,6 @@ const UpcomingEventsList: React.FC = () => {
8673

8774
const loadMoreEvents = () => {
8875
setMaxRange((counter) => counter + eventsPerLoad)
89-
setIsVisible(maxRange + eventsPerLoad <= orderedUpcomingEvents.length)
9076
trackCustomEvent({
9177
eventCategory: "more events button",
9278
eventAction: "click",
@@ -151,7 +137,7 @@ const UpcomingEventsList: React.FC = () => {
151137
maxWidth="620px"
152138
marginTop="5"
153139
>
154-
{isVisible && (
140+
{maxRange <= orderedUpcomingEvents.length && (
155141
<Button onClick={loadMoreEvents}>
156142
<Translation id="page-community:page-community-upcoming-events-load-more" />
157143
</Button>

src/data/community-events.json

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

0 commit comments

Comments
 (0)