1
1
import { useEffect , useState } from "react"
2
+ import { useTranslation } from "next-i18next"
2
3
import { Box } from "@chakra-ui/react"
3
4
4
- import Translation from "@/components/Translation"
5
+ import type { CommunityConference } from "@/lib/types"
6
+
7
+ import { Button } from "@/components/Buttons"
8
+ import EventCard from "@/components/EventCard"
9
+ import InfoBanner from "@/components/InfoBanner"
10
+ import InlineLink from "@/components/Link"
5
11
6
12
import { trackCustomEvent } from "@/lib/utils/matomo"
7
13
8
- import events from "../data/community-events.json"
9
-
10
- import { Button } from "./Buttons"
11
- import EventCard from "./EventCard"
12
- import InfoBanner from "./InfoBanner"
13
- import InlineLink from "./Link"
14
-
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
- }
14
+ import communityConferences from "@/data/community-events"
24
15
25
- interface IOrderedUpcomingEventType extends ICommunityEventData {
16
+ type OrderedUpcomingEvent = CommunityConference & {
26
17
date : string
27
18
formattedDetails : string
28
19
}
29
20
30
- const UpcomingEventsList : React . FC = ( ) => {
21
+ const UpcomingEventsList = ( ) => {
22
+ const { t } = useTranslation ( "page-community" )
31
23
const eventsPerLoad = 10
32
24
const [ orderedUpcomingEvents , setOrderedUpcomingEvents ] = useState <
33
- Array < IOrderedUpcomingEventType >
25
+ OrderedUpcomingEvent [ ]
34
26
> ( [ ] )
35
27
const [ maxRange , setMaxRange ] = useState < number > ( eventsPerLoad )
36
- const [ isVisible , setIsVisible ] = useState < boolean > ( true )
37
28
38
29
// Create Date object from each YYYY-MM-DD JSON date string
39
30
const dateParse = ( dateString : string ) : Date => {
@@ -46,7 +37,7 @@ const UpcomingEventsList: React.FC = () => {
46
37
}
47
38
48
39
useEffect ( ( ) => {
49
- const eventsList : Array < ICommunityEventData > = [ ...events ]
40
+ const eventsList : CommunityConference [ ] = [ ...communityConferences ]
50
41
const yesterday = new Date ( )
51
42
yesterday . setDate ( yesterday . getDate ( ) - 1 )
52
43
@@ -70,9 +61,7 @@ const UpcomingEventsList: React.FC = () => {
70
61
event . endDate
71
62
) . toLocaleDateString ( ) } `
72
63
73
- const details = `${ event . sponsor ? "(" + event . sponsor + ")" : "" } ${
74
- event . description
75
- } `
64
+ const details = `${ event . description } `
76
65
77
66
return {
78
67
...event ,
@@ -86,7 +75,6 @@ const UpcomingEventsList: React.FC = () => {
86
75
87
76
const loadMoreEvents = ( ) => {
88
77
setMaxRange ( ( counter ) => counter + eventsPerLoad )
89
- setIsVisible ( maxRange + eventsPerLoad <= orderedUpcomingEvents . length )
90
78
trackCustomEvent ( {
91
79
eventCategory : "more events button" ,
92
80
eventAction : "click" ,
@@ -97,9 +85,9 @@ const UpcomingEventsList: React.FC = () => {
97
85
if ( orderedUpcomingEvents . length === 0 ) {
98
86
return (
99
87
< InfoBanner emoji = ":information_source:" >
100
- < Translation id = "page-community-upcoming-events-no-events" /> { " " }
88
+ { t ( "page-community-upcoming-events-no-events" ) } { " " }
101
89
< InlineLink to = "https://github.com/ethereum/ethereum-org-website/blob/dev/src/data/community-events.json" >
102
- < Translation id = "page-community:page-community- please-add-to-page" />
90
+ { t ( "page-community- please-add-to-page" ) }
103
91
</ InlineLink >
104
92
</ InfoBanner >
105
93
)
@@ -151,9 +139,9 @@ const UpcomingEventsList: React.FC = () => {
151
139
maxWidth = "620px"
152
140
marginTop = "5"
153
141
>
154
- { isVisible && (
142
+ { maxRange <= orderedUpcomingEvents . length && (
155
143
< Button onClick = { loadMoreEvents } >
156
- < Translation id = "page-community:page-community- upcoming-events-load-more" />
144
+ { t ( "page-community- upcoming-events-load-more" ) }
157
145
</ Button >
158
146
) }
159
147
</ Box >
0 commit comments