1
|
|
|
import axios from "axios" |
2
|
|
|
import classNames from "classnames" |
3
|
|
|
import { graphql, useStaticQuery } from "gatsby" |
4
|
|
|
import { StaticImage } from "gatsby-plugin-image" |
5
|
|
|
import moment from "moment-timezone" |
6
|
|
|
import "moment-timezone/node_modules/moment/locale/nl-be" |
7
|
|
|
import React, { Fragment, FunctionComponent, useEffect, useState } from "react" |
8
|
|
|
import LazyLoad from "react-lazyload" |
9
|
|
|
|
10
|
|
|
import { mapPsdStatus } from "../scripts/helper" |
11
|
|
|
import "./MatchTeaser.scss" |
12
|
|
|
import "./MatchesPreseason.scss" |
13
|
|
|
import "./MatchesScheurkalender.scss" |
14
|
|
|
import Spinner from "./Spinner" |
15
|
|
|
|
16
|
|
|
const MatchesScheurkalenderOverview: FunctionComponent = () => { |
17
|
|
|
const [dataA, setDataA] = useState<Match[]>([]) |
18
|
|
|
const [dataB, setDataB] = useState<Match[]>([]) |
19
|
|
|
|
20
|
|
|
const { |
21
|
|
|
site: { |
22
|
|
|
siteMetadata: { kcvvPsdApi }, |
23
|
|
|
}, |
24
|
|
|
}: MatchesQueryData = useStaticQuery(graphql` |
25
|
|
|
{ |
26
|
|
|
site { |
27
|
|
|
siteMetadata { |
28
|
|
|
kcvvPsdApi |
29
|
|
|
} |
30
|
|
|
} |
31
|
|
|
} |
32
|
|
|
`) |
33
|
|
|
|
34
|
|
|
useEffect(() => { |
35
|
|
|
async function getDataA() { |
36
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/1`) |
37
|
|
|
setDataA(response.data) |
38
|
|
|
} |
39
|
|
|
async function getDataB() { |
40
|
|
|
const response = await axios.get(`${kcvvPsdApi}/matches/2`) |
41
|
|
|
setDataB(response.data) |
42
|
|
|
} |
43
|
|
|
getDataA() |
44
|
|
|
getDataB() |
45
|
|
|
}, []) |
46
|
|
|
|
47
|
|
|
const data = dataA.concat(dataB) |
48
|
|
|
|
49
|
|
|
return ( |
50
|
|
|
<div className={`scheurkalender__wrapper`}> |
51
|
|
|
{data.length > 0 || <Spinner />} |
52
|
|
|
{data |
53
|
|
|
.filter((match: Match) => match.competitionType === `Competitie`) |
54
|
|
|
.sort((a: Match, b: Match) => a.timestamp - b.timestamp) |
55
|
|
|
.map((match: Match) => ( |
56
|
|
|
<MatchTeaserDetail match={match} key={match.id} /> |
57
|
|
|
))} |
58
|
|
|
</div> |
59
|
|
|
) |
60
|
|
|
} |
61
|
|
|
|
62
|
|
|
const MatchTeaserDetail: FunctionComponent<MatchTeaserDetailProps> = ({ match }: MatchTeaserDetailProps) => { |
63
|
|
|
moment.tz.setDefault(`Europe/Brussels`) |
64
|
|
|
moment.locale(`nl-be`) |
65
|
|
|
moment.localeData(`nl-be`) |
66
|
|
|
|
67
|
|
|
const d = moment(match.date) |
68
|
|
|
const matchPlayed = |
69
|
|
|
((match.status === 0 || match.status === null) && match.goalsHomeTeam !== null && match.goalsAwayTeam !== null) || |
70
|
|
|
false |
71
|
|
|
|
72
|
|
|
return ( |
73
|
|
|
<article className="match__teaser"> |
74
|
|
|
<header> |
75
|
|
|
<div className="match__teaser__series"> |
76
|
|
|
{(match.homeTeamId === 1 || match.awayTeamId === 1) && `2e Prov. A`} |
77
|
|
|
{(match.homeTeamId === 2 || match.awayTeamId === 2) && `4e Prov. E`} |
78
|
|
|
</div> |
79
|
|
|
<div> |
80
|
|
|
{match.status !== 0 && ( |
81
|
|
|
<Fragment> |
82
|
|
|
<time |
83
|
|
|
className="match__teaser__datetime match__teaser__datetime--date" |
84
|
|
|
dateTime={d.format(`YYYY-MM-DD - H:mm`)} |
85
|
|
|
> |
86
|
|
|
{d.format(`dddd DD MMMM - H:mm`)} |
87
|
|
|
</time> |
88
|
|
|
<span className="match__teaser__datetime match__teaser__datetime--status"> |
89
|
|
|
{mapPsdStatus(match.status)} |
90
|
|
|
</span> |
91
|
|
|
</Fragment> |
92
|
|
|
)} |
93
|
|
|
{(match.status === 0 || match.status === null) && ( |
94
|
|
|
<Fragment> |
95
|
|
|
<time className="match__teaser__datetime match__teaser__datetime--date" dateTime={d.format(`YYYY-MM-DD`)}> |
96
|
|
|
{d.format(`dddd DD MMMM`)} |
97
|
|
|
</time> |
98
|
|
|
<time className="match__teaser__datetime match__teaser__datetime--time" dateTime={d.format(`H:mm`)}> |
99
|
|
|
{d.format(`H:mm`)} |
100
|
|
|
</time> |
101
|
|
|
</Fragment> |
102
|
|
|
)} |
103
|
|
|
</div> |
104
|
|
|
</header> |
105
|
|
|
<main> |
106
|
|
|
<div |
107
|
|
|
className={classNames(`match__teaser__team`, `match__teaser__team--home`, { |
108
|
|
|
"match__teaser__team--winner": matchPlayed && match.goalsHomeTeam > match.goalsAwayTeam, |
109
|
|
|
})} |
110
|
|
|
> |
111
|
|
|
{match.homeTeamId === null && ( |
112
|
|
|
<LazyLoad debounce={false}> |
113
|
|
|
<img |
114
|
|
|
src={match.homeClub?.logo} |
115
|
|
|
alt={match.homeClub?.name} |
116
|
|
|
className="match__teaser__logo match__teaser__logo--home" |
117
|
|
|
/> |
118
|
|
|
</LazyLoad> |
119
|
|
|
)} |
120
|
|
|
{(match.homeTeamId === 1 || match.homeTeamId === 2) && ( |
121
|
|
|
<StaticImage src="../images/logo-flat.png" alt="KCVV ELEWIJT" width={350} /> |
122
|
|
|
)} |
123
|
|
|
<div> |
124
|
|
|
{match.homeClub?.name.replace(`Kcvv`, `KCVV`)} |
125
|
|
|
{` `} |
126
|
|
|
{match.homeTeamId === null || (match.homeTeamId === 1 ? `A` : `B`)} |
127
|
|
|
</div> |
128
|
|
|
</div> |
129
|
|
|
|
130
|
|
|
{matchPlayed || <span className="match__teaser__vs">-</span>} |
131
|
|
|
{matchPlayed && ( |
132
|
|
|
<span className="match__teaser__vs match__teaser__vs--score"> |
133
|
|
|
{match.goalsHomeTeam} - {match.goalsAwayTeam} |
134
|
|
|
</span> |
135
|
|
|
)} |
136
|
|
|
|
137
|
|
|
<div |
138
|
|
|
className={classNames(`match__teaser__team`, `match__teaser__team--away`, { |
139
|
|
|
"match__teaser__team--winner": matchPlayed && match.goalsHomeTeam < match.goalsAwayTeam, |
140
|
|
|
})} |
141
|
|
|
> |
142
|
|
|
<div> |
143
|
|
|
{match.awayClub?.name.replace(`Kcvv`, `KCVV`)} |
144
|
|
|
{` `} |
145
|
|
|
{match.awayTeamId === null || (match.awayTeamId === 1 ? `A` : `B`)} |
146
|
|
|
</div> |
147
|
|
|
|
148
|
|
|
{match.awayTeamId === null && ( |
149
|
|
|
<LazyLoad debounce={false}> |
150
|
|
|
<img |
151
|
|
|
src={match.awayClub?.logo} |
152
|
|
|
alt={match.awayClub?.name} |
153
|
|
|
className="match__teaser__logo match__teaser__logo--away" |
154
|
|
|
/> |
155
|
|
|
</LazyLoad> |
156
|
|
|
)} |
157
|
|
|
{(match.awayTeamId === 1 || match.awayTeamId === 2) && ( |
158
|
|
|
<StaticImage src="../images/logo-flat.png" alt="KCVV ELEWIJT" width={350} /> |
159
|
|
|
)} |
160
|
|
|
</div> |
161
|
|
|
</main> |
162
|
|
|
</article> |
163
|
|
|
) |
164
|
|
|
} |
165
|
|
|
|
166
|
|
|
export default MatchesScheurkalenderOverview |
167
|
|
|
|