1
|
|
|
import axios from "axios" |
2
|
|
|
import moment from "moment" |
3
|
|
|
import "moment-timezone" |
4
|
|
|
import "moment/locale/nl-be" |
5
|
|
|
import React from "react" |
6
|
|
|
import { useEffect, useState } from "react" |
7
|
|
|
import { useSiteMetaData } from "../hooks/use-site-metadata" |
8
|
|
|
import { Match, MatchesProps, MatchesRowProps } from "../Types/Match" |
9
|
|
|
import { Spinner } from "./Spinner" |
10
|
|
|
import "./Matches.scss" |
11
|
|
|
import classnames from "classnames" |
12
|
|
|
import LazyLoad from "react-lazyload" |
13
|
|
|
import { mapPsdStatus, mapPsdStatusShort } from "../scripts/helper" |
14
|
|
|
import { Link } from "gatsby" |
15
|
|
|
import Icon from "./Icon" |
16
|
|
|
|
17
|
|
|
const Matches = ({ teamId }: MatchesProps) => { |
18
|
|
|
const { kcvvPsdApi } = useSiteMetaData() |
19
|
|
|
const [data, setData] = useState<Match[]>([]) |
20
|
|
|
|
21
|
|
|
useEffect(() => { |
22
|
|
|
async function getData() { |
23
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/${teamId}`) |
24
|
|
|
setData(response.data) |
25
|
|
|
} |
26
|
|
|
getData() |
27
|
|
|
}, [kcvvPsdApi, teamId]) |
28
|
|
|
|
29
|
|
|
return ( |
30
|
|
|
<div className="matches__wrapper"> |
31
|
|
|
{data.length > 0 || <Spinner />} |
32
|
|
|
{data |
33
|
|
|
.sort((a, b) => a.timestamp - b.timestamp) |
34
|
|
|
.map((match, i) => ( |
35
|
|
|
<MatchesRow match={match} /> |
36
|
|
|
))} |
37
|
|
|
</div> |
38
|
|
|
) |
39
|
|
|
} |
40
|
|
|
|
41
|
|
|
const MatchesRow = ({ match }: MatchesRowProps) => { |
42
|
|
|
moment.tz.setDefault(`Europe/Brussels`) |
43
|
|
|
moment.locale(`nl-be`) |
44
|
|
|
moment.localeData(`nl-be`) |
45
|
|
|
|
46
|
|
|
const d = moment(match.date) |
47
|
|
|
const date = d.format(`ddd D MMM`) |
48
|
|
|
const time = d.format(`HH:mm`) |
49
|
|
|
const matchPlayed = |
50
|
|
|
((match.status === 0 || match.status === null) && match.goalsHomeTeam !== null && match.goalsAwayTeam !== null) || |
51
|
|
|
false |
52
|
|
|
const sideTeam = match.homeTeamId ? `home` : `away` |
53
|
|
|
|
54
|
|
|
return ( |
55
|
|
|
<div className="matches__row"> |
56
|
|
|
<article className="matches__match"> |
57
|
|
|
<div className="matches__competition__wrapper"> |
58
|
|
|
<span className="matches__competition__type">{match.competitionType}</span> |
59
|
|
|
</div> |
60
|
|
|
<div className="matches__date__wrapper"> |
61
|
|
|
<span className="matches__date__date">{date}</span> |
62
|
|
|
<span className="matches__date__time">{time}</span> |
63
|
|
|
</div> |
64
|
|
|
<div |
65
|
|
|
className={classnames(`matches__team__wrapper`, `matches__team__wrapper--home`, { |
66
|
|
|
"matches__team__wrapper--elewijt": match.homeTeamId, |
67
|
|
|
})} |
68
|
|
|
> |
69
|
|
|
<div className="matches__team__name"> |
70
|
|
|
{match.homeClub?.abbreviation || match.homeClub?.name} |
71
|
|
|
{` `} |
72
|
|
|
<span className="matches__team__home_indicator" title="Uitwedstrijd"> |
73
|
|
|
(U) |
74
|
|
|
</span> |
75
|
|
|
</div> |
76
|
|
|
<div className="matches__team__logo"> |
77
|
|
|
<LazyLoad debounce={false}> |
78
|
|
|
<img |
79
|
|
|
src={match.homeClub?.logo} |
80
|
|
|
alt={match.homeClub?.abbreviation} |
81
|
|
|
className="match__teaser__logo match__teaser__logo--home" |
82
|
|
|
/> |
83
|
|
|
</LazyLoad> |
84
|
|
|
</div> |
85
|
|
|
</div> |
86
|
|
|
<div className="matches__score__wrapper"> |
87
|
|
|
{match.status !== 0 && ( |
88
|
|
|
<span className="matches__score matches__score--status" title={mapPsdStatus(match.status) || ``}> |
89
|
|
|
{mapPsdStatusShort(match.status)} |
90
|
|
|
</span> |
91
|
|
|
)} |
92
|
|
|
{(match.status === 0 || match.status === null) && !matchPlayed && ( |
93
|
|
|
<span className="matches__score matches__score--vs">VS</span> |
94
|
|
|
)} |
95
|
|
|
{matchPlayed && ( |
96
|
|
|
<> |
97
|
|
|
<span className="matches__score matches__score--score"> |
98
|
|
|
<span>{match.goalsHomeTeam}</span> <span>-</span> <span>{match.goalsAwayTeam}</span> |
99
|
|
|
{/* {match.goalsHomeTeam} - {match.goalsAwayTeam} */} |
100
|
|
|
</span> |
101
|
|
|
{/* className={classnames(`matches__score_result`, { |
102
|
|
|
"matches__score_result--draw": match.goalsHomeTeam === match.goalsAwayTeam, |
103
|
|
|
"matches__score_result--loss": |
104
|
|
|
sideTeam === `home` |
105
|
|
|
? match.goalsAwayTeam > match.goalsHomeTeam |
106
|
|
|
: match.goalsHomeTeam > match.goalsAwayTeam, |
107
|
|
|
"matches__score_result--win": |
108
|
|
|
sideTeam === `home` |
109
|
|
|
? match.goalsHomeTeam > match.goalsAwayTeam |
110
|
|
|
: match.goalsAwayTeam > match.goalsHomeTeam, |
111
|
|
|
})} |
112
|
|
|
> */} |
113
|
|
|
{/* {(sideTeam === `home` |
114
|
|
|
? match.goalsAwayTeam > match.goalsHomeTeam |
115
|
|
|
: match.goalsHomeTeam > match.goalsAwayTeam) && ( |
116
|
|
|
<span className="matches__score_result matches__score_result--loss">Verlies</span> |
117
|
|
|
)} |
118
|
|
|
{(sideTeam === `home` |
119
|
|
|
? match.goalsHomeTeam > match.goalsAwayTeam |
120
|
|
|
: match.goalsAwayTeam > match.goalsHomeTeam) && ( |
121
|
|
|
<span className="matches__score_result matches__score_result--win">Winst</span> |
122
|
|
|
)} |
123
|
|
|
{match.goalsAwayTeam === match.goalsHomeTeam && ( |
124
|
|
|
<span className="matches__score_result matches__score_result--draw">Gelijk</span> |
125
|
|
|
)} */} |
126
|
|
|
{/* </span> */} |
127
|
|
|
</> |
128
|
|
|
)} |
129
|
|
|
</div> |
130
|
|
|
<div |
131
|
|
|
className={classnames(`matches__team__wrapper`, `matches__team__wrapper--away`, { |
132
|
|
|
"matches__team__wrapper--elewijt": match.awayTeamId, |
133
|
|
|
})} |
134
|
|
|
> |
135
|
|
|
<div className="matches__team__name"> |
136
|
|
|
{match.awayClub?.abbreviation || match.awayClub?.name} |
137
|
|
|
{` `} |
138
|
|
|
<span className="matches__team__home_indicator" title="Thuiswedstrijd"> |
139
|
|
|
(T) |
140
|
|
|
</span> |
141
|
|
|
</div> |
142
|
|
|
<div className="matches__team__logo"> |
143
|
|
|
<LazyLoad debounce={false}> |
144
|
|
|
<img |
145
|
|
|
src={match.awayClub?.logo} |
146
|
|
|
alt={match.awayClub?.abbreviation} |
147
|
|
|
className="match__teaser__logo match__teaser__logo--away" |
148
|
|
|
/> |
149
|
|
|
</LazyLoad> |
150
|
|
|
</div> |
151
|
|
|
</div> |
152
|
|
|
<div className="matches__info__wrapper"> |
153
|
|
|
<Link to={`/game/${match.id}`} className="matches__calendar__link"> |
154
|
|
|
<Icon icon="fa-info-circle" /> Verslag |
155
|
|
|
</Link> |
156
|
|
|
</div> |
157
|
|
|
</article> |
158
|
|
|
{/* <header className="matches__calendar__title"> |
159
|
|
|
<h3> |
160
|
|
|
<span className="matches__calendar__date">{date}</span> |
161
|
|
|
<span className="matches__calendar__separator">|</span> |
162
|
|
|
<span className="matches__calendar__type">{match.competitionType}</span> |
163
|
|
|
</h3> |
164
|
|
|
</header> */} |
165
|
|
|
{/* <main className="matches__calendar__main"> |
166
|
|
|
<div |
167
|
|
|
className={classNames(`matches__calendar__team`, `matches__calendar__team--home`, { |
168
|
|
|
"matches__calendar__team--winner": matchPlayed && match.goalsHomeTeam > match.goalsAwayTeam, |
169
|
|
|
})} |
170
|
|
|
> |
171
|
|
|
{match.homeClub?.abbreviation || match.homeClub?.name} |
172
|
|
|
<LazyLoad debounce={false}> |
173
|
|
|
<img |
174
|
|
|
src={match.homeClub?.logo} |
175
|
|
|
alt={match.homeClub?.name} |
176
|
|
|
className="matches__calendar__logo matches__calendar__logo--home" |
177
|
|
|
/> |
178
|
|
|
</LazyLoad> |
179
|
|
|
</div> |
180
|
|
|
|
181
|
|
|
<div className="matches__calendar__score"> |
182
|
|
|
{match.status !== 0 && ( |
183
|
|
|
<span title={mapPsdStatus(match.status) || ``}>{mapPsdStatusShort(match.status)}</span> |
184
|
|
|
)} |
185
|
|
|
{(match.status === 0 || match.status === null) && !matchPlayed && <span>{time}</span>} |
186
|
|
|
{matchPlayed && ( |
187
|
|
|
<span> |
188
|
|
|
{match.goalsHomeTeam} - {match.goalsAwayTeam} |
189
|
|
|
</span> |
190
|
|
|
)} |
191
|
|
|
</div> |
192
|
|
|
|
193
|
|
|
<div |
194
|
|
|
className={classNames(`matches__calendar__team`, `matches__calendar__team--away`, { |
195
|
|
|
"matches__calendar__team--winner": matchPlayed && match.goalsHomeTeam < match.goalsAwayTeam, |
196
|
|
|
})} |
197
|
|
|
> |
198
|
|
|
<LazyLoad debounce={false}> |
199
|
|
|
<img |
200
|
|
|
src={match.awayClub?.logo} |
201
|
|
|
alt={match.awayClub?.name} |
202
|
|
|
className="matches__calendar__logo matches__calendar__logo--away" |
203
|
|
|
/> |
204
|
|
|
</LazyLoad> |
205
|
|
|
|
206
|
|
|
{match.awayClub?.abbreviation || match.awayClub?.name} |
207
|
|
|
</div> |
208
|
|
|
|
209
|
|
|
<Link to={`/game/${match.id}`} className="matches__calendar__link"> |
210
|
|
|
<Icon icon="fa-info-circle" /> |
211
|
|
|
</Link> |
212
|
|
|
</main> */} |
213
|
|
|
</div> |
214
|
|
|
) |
215
|
|
|
} |
216
|
|
|
|
217
|
|
|
export default Matches |
218
|
|
|
|