1
|
|
|
import React, { FunctionComponent, useEffect, useState, Fragment } from "react" |
2
|
|
|
import { graphql, useStaticQuery } from "gatsby" |
3
|
|
|
|
4
|
|
|
import "./MatchTeaser.scss" |
5
|
|
|
import MiniRanking from "./MiniRanking" |
6
|
|
|
|
7
|
|
|
import axios from "axios" |
8
|
|
|
import LazyLoad from "react-lazyload" |
9
|
|
|
import classNames from "classnames" |
10
|
|
|
import Moment from "moment-timezone" |
11
|
|
|
import "moment/locale/nl-be" |
12
|
|
|
|
13
|
|
|
import { capitalizeFirstLetter, mapPsdStatus, mapPsdStatusShort } from "../scripts/helper" |
14
|
|
|
|
15
|
|
|
import "./MatchesPreseason.scss" |
16
|
|
|
import "./MatchesScheurkalender.scss" |
17
|
|
|
import Spinner from "./Spinner" |
18
|
|
|
import { StaticImage } from "gatsby-plugin-image" |
19
|
|
|
|
20
|
|
|
const MatchOverviewMatch: FunctionComponent<MatchesRowProps> = ({ match }: MatchesRowProps) => { |
21
|
|
|
const d = Moment.tz(match.date, `Europe/Brussels`) |
22
|
|
|
const matchPlayed = |
23
|
|
|
((match.status === 0 || match.status === null) && match.goalsHomeTeam !== null && match.goalsAwayTeam !== null) || |
24
|
|
|
false |
25
|
|
|
|
26
|
|
|
return ( |
27
|
|
|
<article> |
28
|
|
|
<main className="matches__calendar__main matches__calendar__preseason"> |
29
|
|
|
<div className="matches__calendar__date matches__preseason__date"> |
30
|
|
|
<span className="matches__calendar__date matches__preseason__date--date">{d.format(`DD`)}</span> |
31
|
|
|
<span className="matches__calendar__date matches__preseason__date--day"> |
32
|
|
|
{capitalizeFirstLetter(d.format(`dddd`))} |
33
|
|
|
</span> |
34
|
|
|
<span className="matches__preseason__divider"> // </span> |
35
|
|
|
<span className="matches__calendar__date matches__preseason__date--day">{d.format(`HH:mm`)}</span> |
36
|
|
|
</div> |
37
|
|
|
|
38
|
|
|
<div className="matches__preseason__match"> |
39
|
|
|
<div |
40
|
|
|
className={classNames(`matches__calendar__team`, `matches__calendar__team--home`, { |
41
|
|
|
"matches__calendar__team--winner": matchPlayed && match.goalsHomeTeam > match.goalsAwayTeam, |
42
|
|
|
})} |
43
|
|
|
> |
44
|
|
|
<LazyLoad debounce={false}> |
45
|
|
|
<img |
46
|
|
|
src={match.homeClub?.logo} |
47
|
|
|
alt={match.homeClub?.name} |
48
|
|
|
className="matches__calendar__logo matches__calendar__logo--home" |
49
|
|
|
/> |
50
|
|
|
</LazyLoad> |
51
|
|
|
{match.homeClub?.name} {match.homeTeamId === null || (match.homeTeamId === 1 ? `A` : `B`)} |
52
|
|
|
</div> |
53
|
|
|
|
54
|
|
|
<div className="matches__calendar__score"> |
55
|
|
|
{match.status !== 0 && ( |
56
|
|
|
<span title={mapPsdStatus(match.status) || ``}>{mapPsdStatusShort(match.status)}</span> |
57
|
|
|
)} |
58
|
|
|
{(match.status === 0 || match.status === null) && !matchPlayed && <span>-</span>} |
59
|
|
|
{matchPlayed && ( |
60
|
|
|
<span> |
61
|
|
|
{match.goalsHomeTeam} - {match.goalsAwayTeam} |
62
|
|
|
</span> |
63
|
|
|
)} |
64
|
|
|
</div> |
65
|
|
|
|
66
|
|
|
<div |
67
|
|
|
className={classNames(`matches__calendar__team`, `matches__calendar__team--away`, { |
68
|
|
|
"matches__calendar__team--winner": matchPlayed && match.goalsHomeTeam < match.goalsAwayTeam, |
69
|
|
|
})} |
70
|
|
|
> |
71
|
|
|
{match.awayClub?.name} {match.awayTeamId === null || (match.awayTeamId === 1 ? `A` : `B`)} |
72
|
|
|
<LazyLoad debounce={false}> |
73
|
|
|
<img |
74
|
|
|
src={match.awayClub?.logo} |
75
|
|
|
alt={match.awayClub?.name} |
76
|
|
|
className="matches__calendar__logo matches__calendar__logo--away" |
77
|
|
|
/> |
78
|
|
|
</LazyLoad> |
79
|
|
|
</div> |
80
|
|
|
</div> |
81
|
|
|
<div className="matches__calendar__type matches__preseason__type">{match.competitionType}</div> |
82
|
|
|
</main> |
83
|
|
|
</article> |
84
|
|
|
) |
85
|
|
|
} |
86
|
|
|
|
87
|
|
|
const MatchesScheurkalenderOverview: FunctionComponent = () => { |
88
|
|
|
const [dataA, setDataA] = useState<Match[]>([]) |
89
|
|
|
const [dataB, setDataB] = useState<Match[]>([]) |
90
|
|
|
|
91
|
|
|
const { |
92
|
|
|
site: { |
93
|
|
|
siteMetadata: { kcvvPsdApi }, |
94
|
|
|
}, |
95
|
|
|
}: MatchesQueryData = useStaticQuery(graphql` |
96
|
|
|
{ |
97
|
|
|
site { |
98
|
|
|
siteMetadata { |
99
|
|
|
kcvvPsdApi |
100
|
|
|
} |
101
|
|
|
} |
102
|
|
|
} |
103
|
|
|
`) |
104
|
|
|
|
105
|
|
|
Moment.locale(`nl-BE`) |
106
|
|
|
|
107
|
|
|
useEffect(() => { |
108
|
|
|
async function getDataA() { |
109
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/1`) |
110
|
|
|
setDataA(response.data) |
111
|
|
|
} |
112
|
|
|
async function getDataB() { |
113
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/2`) |
114
|
|
|
setDataB(response.data) |
115
|
|
|
} |
116
|
|
|
getDataA() |
117
|
|
|
getDataB() |
118
|
|
|
}, []) |
119
|
|
|
|
120
|
|
|
const data = dataA.concat(dataB) |
121
|
|
|
|
122
|
|
|
return ( |
123
|
|
|
<div className={`scheurkalender__wrapper`}> |
124
|
|
|
{data.length > 0 || <Spinner />} |
125
|
|
|
{data |
126
|
|
|
.filter((match: Match) => match.competitionType === `Competitie`) |
127
|
|
|
.sort((a: Match, b: Match) => a.timestamp - b.timestamp) |
128
|
|
|
.map((match: Match) => ( |
129
|
|
|
<MatchTeaserDetail match={match} key={match.id} /> |
130
|
|
|
))} |
131
|
|
|
</div> |
132
|
|
|
) |
133
|
|
|
} |
134
|
|
|
|
135
|
|
|
const MatchTeaserDetail: FunctionComponent<MatchTeaserDetailProps> = ({ |
136
|
|
|
match, |
137
|
|
|
includeRankings = false, |
138
|
|
|
}: MatchTeaserDetailProps) => { |
139
|
|
|
Moment.locale(`nl-BE`) |
140
|
|
|
const d = Moment.tz(match.date, `Europe/Brussels`) |
141
|
|
|
const matchPlayed = |
142
|
|
|
((match.status === 0 || match.status === null) && match.goalsHomeTeam !== null && match.goalsAwayTeam !== null) || |
143
|
|
|
false |
144
|
|
|
|
145
|
|
|
return ( |
146
|
|
|
<article className="match__teaser"> |
147
|
|
|
<header> |
148
|
|
|
<div className="match__teaser__series"> |
149
|
|
|
{(match.homeTeamId === 1 || match.awayTeamId === 1) && `2e Prov. A`} |
150
|
|
|
{(match.homeTeamId === 2 || match.awayTeamId === 2) && `4e Prov. E`} |
151
|
|
|
</div> |
152
|
|
|
<div> |
153
|
|
|
{match.status !== 0 && ( |
154
|
|
|
<Fragment> |
155
|
|
|
<time |
156
|
|
|
className="match__teaser__datetime match__teaser__datetime--date" |
157
|
|
|
dateTime={d.format(`YYYY-MM-DD - H:mm`)} |
158
|
|
|
> |
159
|
|
|
{d.format(`dddd DD MMMM - H:mm`)} |
160
|
|
|
</time> |
161
|
|
|
<span className="match__teaser__datetime match__teaser__datetime--status"> |
162
|
|
|
{mapPsdStatus(match.status)} |
163
|
|
|
</span> |
164
|
|
|
</Fragment> |
165
|
|
|
)} |
166
|
|
|
{(match.status === 0 || match.status === null) && ( |
167
|
|
|
<Fragment> |
168
|
|
|
<time className="match__teaser__datetime match__teaser__datetime--date" dateTime={d.format(`YYYY-MM-DD`)}> |
169
|
|
|
{d.format(`dddd DD MMMM`)} |
170
|
|
|
</time> |
171
|
|
|
<time className="match__teaser__datetime match__teaser__datetime--time" dateTime={d.format(`H:mm`)}> |
172
|
|
|
{d.format(`H:mm`)} |
173
|
|
|
</time> |
174
|
|
|
</Fragment> |
175
|
|
|
)} |
176
|
|
|
</div> |
177
|
|
|
</header> |
178
|
|
|
<main> |
179
|
|
|
<div |
180
|
|
|
className={classNames(`match__teaser__team`, `match__teaser__team--home`, { |
181
|
|
|
"match__teaser__team--winner": matchPlayed && match.goalsHomeTeam > match.goalsAwayTeam, |
182
|
|
|
})} |
183
|
|
|
> |
184
|
|
|
{match.homeTeamId === null && ( |
185
|
|
|
<LazyLoad debounce={false}> |
186
|
|
|
<img |
187
|
|
|
src={match.homeClub?.logo} |
188
|
|
|
alt={match.homeClub?.name} |
189
|
|
|
className="match__teaser__logo match__teaser__logo--home" |
190
|
|
|
/> |
191
|
|
|
</LazyLoad> |
192
|
|
|
)} |
193
|
|
|
{(match.homeTeamId === 1 || match.homeTeamId === 2) && ( |
194
|
|
|
<StaticImage src="../images/logo-flat.png" alt="KCVV ELEWIJT" width={350}/> |
195
|
|
|
)} |
196
|
|
|
<div> |
197
|
|
|
{match.homeClub?.name.replace(`Kcvv`, `KCVV`)} |
198
|
|
|
{` `} |
199
|
|
|
{match.homeTeamId === null || (match.homeTeamId === 1 ? `A` : `B`)} |
200
|
|
|
</div> |
201
|
|
|
</div> |
202
|
|
|
|
203
|
|
|
{matchPlayed || <span className="match__teaser__vs">-</span>} |
204
|
|
|
{matchPlayed && ( |
205
|
|
|
<span className="match__teaser__vs match__teaser__vs--score"> |
206
|
|
|
{match.goalsHomeTeam} - {match.goalsAwayTeam} |
207
|
|
|
</span> |
208
|
|
|
)} |
209
|
|
|
|
210
|
|
|
<div |
211
|
|
|
className={classNames(`match__teaser__team`, `match__teaser__team--away`, { |
212
|
|
|
"match__teaser__team--winner": matchPlayed && match.goalsHomeTeam < match.goalsAwayTeam, |
213
|
|
|
})} |
214
|
|
|
> |
215
|
|
|
<div> |
216
|
|
|
{match.awayClub?.name.replace(`Kcvv`, `KCVV`)} |
217
|
|
|
{` `} |
218
|
|
|
{match.awayTeamId === null || (match.awayTeamId === 1 ? `A` : `B`)} |
219
|
|
|
</div> |
220
|
|
|
|
221
|
|
|
{match.awayTeamId === null && ( |
222
|
|
|
<LazyLoad debounce={false}> |
223
|
|
|
<img |
224
|
|
|
src={match.awayClub?.logo} |
225
|
|
|
alt={match.awayClub?.name} |
226
|
|
|
className="match__teaser__logo match__teaser__logo--away" |
227
|
|
|
/> |
228
|
|
|
</LazyLoad> |
229
|
|
|
)} |
230
|
|
|
{(match.awayTeamId === 1 || match.awayTeamId === 2) && ( |
231
|
|
|
<StaticImage src="../images/logo-flat.png" alt="KCVV ELEWIJT" width={350} /> |
232
|
|
|
)} |
233
|
|
|
</div> |
234
|
|
|
</main> |
235
|
|
|
{includeRankings && ( |
236
|
|
|
<MiniRanking |
237
|
|
|
teamId={match.homeTeamId || match.awayTeamId} |
238
|
|
|
homeTeam={match.homeClub?.name} |
239
|
|
|
awayTeam={match.awayClub?.name} |
240
|
|
|
/> |
241
|
|
|
)} |
242
|
|
|
</article> |
243
|
|
|
) |
244
|
|
|
} |
245
|
|
|
|
246
|
|
|
export default MatchesScheurkalenderOverview |
247
|
|
|
|