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