1
|
|
|
import { graphql } from "gatsby" |
2
|
|
|
import React, { Fragment } from "react" |
3
|
|
|
import SEO from "../components/seo" |
4
|
|
|
import Layout from "../layouts/index" |
5
|
|
|
import Img from "gatsby-image" |
6
|
|
|
import { TeamSection } from "../components/team--section" |
7
|
|
|
import "./team.scss" |
8
|
|
|
import TeamCalendarMatches from "../components/team-calendar-matches" |
9
|
|
|
import TeamCalendarMetaMatches from "../components/team-calendar-meta-matches" |
10
|
|
|
|
11
|
|
|
import Ranking from "../components/Ranking" |
12
|
|
|
import TeamStats from "../components/TeamStats" |
13
|
|
|
|
14
|
|
|
// Generic helper function to group an array by a property. |
15
|
|
|
const groupBy = (key) => (array) => |
16
|
|
|
array.reduce((objectsByKeyValue, obj) => { |
17
|
|
|
const value = obj[key] |
18
|
|
|
objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj) |
19
|
|
|
return objectsByKeyValue |
20
|
|
|
}, {}) |
21
|
|
|
|
22
|
|
|
// Specific implementation of our groupBy function, to group by a property "field_position". |
23
|
|
|
const groupByPosition = groupBy(`field_position`) |
24
|
|
|
|
25
|
|
|
const TeamTemplate = ({ data }) => { |
26
|
|
|
const node = data.nodeTeam |
27
|
|
|
|
28
|
|
|
// If we have players, group them by their position. |
29
|
|
|
const playersByPosition = |
30
|
|
|
node.relationships.field_players.length > 0 && groupByPosition(node.relationships.field_players) |
31
|
|
|
|
32
|
|
|
const picture = node.relationships.field_media_article_image |
33
|
|
|
// Create a fluid/responsive team image instance. |
34
|
|
|
const teamPicture = picture && ( |
35
|
|
|
<Img |
36
|
|
|
fluid={picture.relationships.field_media_image.localFile.childImageSharp.fluid} |
37
|
|
|
alt={picture.field_media_image.alt} |
38
|
|
|
className={`team-detail__team-picture`} |
39
|
|
|
/> |
40
|
|
|
) |
41
|
|
|
|
42
|
|
|
// Helper variable so we don't have to do the check over and over again. |
43
|
|
|
const hasDivision = node.field_fb_id || node.field_fb_id_2 |
44
|
|
|
|
45
|
|
|
const pathUrl = node.path.alias |
46
|
|
|
const ogImage = picture && { |
47
|
|
|
src: |
48
|
|
|
node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp.resize.src, |
49
|
|
|
width: |
50
|
|
|
node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp.resize |
51
|
|
|
.width, |
52
|
|
|
height: |
53
|
|
|
node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp.resize |
54
|
|
|
.height, |
55
|
|
|
} |
56
|
|
|
|
57
|
|
|
return ( |
58
|
|
|
<Layout> |
59
|
|
|
<SEO |
60
|
|
|
lang="nl-BE" |
61
|
|
|
title={node.title + ` / ` + node.field_division_full} |
62
|
|
|
description={`KCVV Elewijt ` + node.field_division_full} |
63
|
|
|
path={pathUrl} |
64
|
|
|
image={ogImage || null} |
65
|
|
|
/> |
66
|
|
|
|
67
|
|
|
<article className={`team-detail`}> |
68
|
|
|
<header className={`team-detail__header`}> |
69
|
|
|
<h1 className={`team-detail__name`}> |
70
|
|
|
{/* > GEWESTELIJKE U13 K */} |
71
|
|
|
<span className={`team-detail__name-division`}>{node.field_division_full}</span> |
72
|
|
|
{/* > The A-team */} |
73
|
|
|
<span className={`team-detail__name-tagline`}>{node.field_tagline}</span> |
74
|
|
|
</h1> |
75
|
|
|
|
76
|
|
|
<div className={`bg-green-mask`}> |
77
|
|
|
<div className={`bg-white-end`} /> |
78
|
|
|
</div> |
79
|
|
|
|
80
|
|
|
{/* > 2A, 2G9K... */} |
81
|
|
|
{/* FB ID if only one of either is set, FB ID 2 if it has a value (will only be published around new year's, so it's always the most relevant as soon as it's known) */} |
82
|
|
|
{hasDivision && ( |
83
|
|
|
<div className={`team-detail__division-number`} aria-hidden="true"> |
84
|
|
|
{node.field_fb_id_2 ? node.field_fb_id_2 : node.field_fb_id} |
85
|
|
|
</div> |
86
|
|
|
)} |
87
|
|
|
</header> |
88
|
|
|
|
89
|
|
|
<div className={`team-break`}></div> |
90
|
|
|
|
91
|
|
|
{/* Only show tab links if there are either players assigned to the team, or the team has an (active) division, so we can show rankings/matches */} |
92
|
|
|
{(playersByPosition || hasDivision) && ( |
93
|
|
|
<section className={`team-sub_navigation`}> |
94
|
|
|
{/* Foundation tabs structure */} |
95
|
|
|
<ul |
96
|
|
|
className={`tabs team-sub_navigation__tabs `} |
97
|
|
|
data-tabs |
98
|
|
|
data-deep-link="true" |
99
|
|
|
data-update-history="true" |
100
|
|
|
data-deep-link-smudge="true" |
101
|
|
|
data-deep-link-smudge-delay="500" |
102
|
|
|
id="team-subnavigation_tabs" |
103
|
|
|
> |
104
|
|
|
<li className="tabs-title is-active"> |
105
|
|
|
<a href="#team-info">Info</a> |
106
|
|
|
</li> |
107
|
|
|
{/* Youth teams don't have lineups, so we don't show the tab link. */} |
108
|
|
|
{playersByPosition && ( |
109
|
|
|
<li className="tabs-title"> |
110
|
|
|
<a href="#team-lineup">Lineup</a> |
111
|
|
|
</li> |
112
|
|
|
)} |
113
|
|
|
{hasDivision && ( |
114
|
|
|
<Fragment> |
115
|
|
|
<li className={`tabs-title`}> |
116
|
|
|
<a data-tabs-target="team-matches" href="#team-matches"> |
117
|
|
|
Wedstrijden |
118
|
|
|
</a> |
119
|
|
|
</li> |
120
|
|
|
<li className={`tabs-title`}> |
121
|
|
|
<a data-tabs-target="team-ranking" href="#team-ranking"> |
122
|
|
|
Stand |
123
|
|
|
</a> |
124
|
|
|
</li> |
125
|
|
|
</Fragment> |
126
|
|
|
)} |
127
|
|
|
</ul> |
128
|
|
|
</section> |
129
|
|
|
)} |
130
|
|
|
|
131
|
|
|
<div className={`tabs-content`} data-tabs-content="team-subnavigation_tabs"> |
132
|
|
|
<div className={`tabs-panel is-active`} id="team-info"> |
133
|
|
|
{teamPicture || ``} |
134
|
|
|
{node.field_contact_info && ( |
135
|
|
|
<div |
136
|
|
|
className={`team-detail__team-info`} |
137
|
|
|
dangerouslySetInnerHTML={{ |
138
|
|
|
__html: node.field_contact_info.processed, |
139
|
|
|
}} |
140
|
|
|
/> |
141
|
|
|
)} |
142
|
|
|
{node.field_vv_id && <TeamStats teamId={node.field_vv_id} />} |
143
|
|
|
</div> |
144
|
|
|
{/* If our page displays staff only (e.g. the "board" page), we change the title. */} |
145
|
|
|
{node.relationships.field_staff && !playersByPosition && ( |
146
|
|
|
<main className={`team-detail__lineup team-detail__lineup--staff-only`}> |
147
|
|
|
<TeamSection title="Stafleden" lineup={node.relationships.field_staff} /> |
148
|
|
|
</main> |
149
|
|
|
)} |
150
|
|
|
{playersByPosition && ( |
151
|
|
|
<div className={`tabs-panel`} id="team-lineup"> |
152
|
|
|
<main className={`team-detail__lineup`}> |
153
|
|
|
{node.relationships.field_staff && ( |
154
|
|
|
<TeamSection title="Stafleden" lineup={node.relationships.field_staff} /> |
155
|
|
|
)} |
156
|
|
|
{playersByPosition[`k`] && <TeamSection title="Doelmannen" lineup={playersByPosition[`k`]} />} |
157
|
|
|
{playersByPosition[`d`] && <TeamSection title="Verdedigers" lineup={playersByPosition[`d`]} />} |
158
|
|
|
{playersByPosition[`m`] && <TeamSection title="Middenvelder" lineup={playersByPosition[`m`]} />} |
159
|
|
|
{playersByPosition[`a`] && <TeamSection title="Aanvallers" lineup={playersByPosition[`a`]} />} |
160
|
|
|
</main> |
161
|
|
|
</div> |
162
|
|
|
)} |
163
|
|
|
{hasDivision && ( |
164
|
|
|
<Fragment> |
165
|
|
|
<div className={`tabs-panel`} id="team-matches"> |
166
|
|
|
{node.field_fb_id_2 && ( |
167
|
|
|
<div className={`team-matches__wrapper`}> |
168
|
|
|
{node.field_fb_id && <h2>Wedstrijden na nieuwjaar</h2>} |
169
|
|
|
|
170
|
|
|
{/* Metamatches is the big banner on top with the previous and next match highlighted. */} |
171
|
|
|
{!node.field_fb_id && ( |
172
|
|
|
<TeamCalendarMetaMatches |
173
|
|
|
season="2021" |
174
|
|
|
region="bra" |
175
|
|
|
division={node.field_fb_id_2} |
176
|
|
|
regnumber="00055" |
177
|
|
|
/> |
178
|
|
|
)} |
179
|
|
|
|
180
|
|
|
<TeamCalendarMatches season="2021" region="bra" division={node.field_fb_id_2} /> |
181
|
|
|
</div> |
182
|
|
|
)} |
183
|
|
|
{node.field_fb_id && ( |
184
|
|
|
<div className={`team-matches__wrapper`}> |
185
|
|
|
{node.field_fb_id_2 && <h2>Wedstrijden voor nieuwjaar</h2>} |
186
|
|
|
|
187
|
|
|
{/* Metamatches is the big banner on top with the previous and next match highlighted. */} |
188
|
|
|
{!node.field_fb_id_2 && ( |
189
|
|
|
<TeamCalendarMetaMatches |
190
|
|
|
season="2021" |
191
|
|
|
region="bra" |
192
|
|
|
division={node.field_fb_id} |
193
|
|
|
regnumber="00055" |
194
|
|
|
/> |
195
|
|
|
)} |
196
|
|
|
|
197
|
|
|
<TeamCalendarMatches season="2021" region="bra" division={node.field_fb_id} /> |
198
|
|
|
</div> |
199
|
|
|
)} |
200
|
|
|
</div> |
201
|
|
|
<div className={`tabs-panel`} id="team-ranking"> |
202
|
|
|
{node.field_vv_id && <Ranking teamId={node.field_vv_id} />} |
203
|
|
|
</div> |
204
|
|
|
</Fragment> |
205
|
|
|
)} |
206
|
|
|
</div> |
207
|
|
|
</article> |
208
|
|
|
</Layout> |
209
|
|
|
) |
210
|
|
|
} |
211
|
|
|
|
212
|
|
|
export const query = graphql` |
213
|
|
|
query($slug: String!) { |
214
|
|
|
nodeTeam(path: { alias: { eq: $slug } }) { |
215
|
|
|
path { |
216
|
|
|
alias |
217
|
|
|
} |
218
|
|
|
title |
219
|
|
|
field_contact_info { |
220
|
|
|
processed |
221
|
|
|
} |
222
|
|
|
field_fb_id |
223
|
|
|
field_fb_id_2 |
224
|
|
|
field_vv_id |
225
|
|
|
field_division_full |
226
|
|
|
field_tagline |
227
|
|
|
relationships { |
228
|
|
|
field_staff { |
229
|
|
|
path { |
230
|
|
|
alias |
231
|
|
|
} |
232
|
|
|
field_position_short |
233
|
|
|
field_lastname |
234
|
|
|
field_firstname |
235
|
|
|
relationships { |
236
|
|
|
field_image { |
237
|
|
|
localFile { |
238
|
|
|
...KCVVFluidPlayerTeaser |
239
|
|
|
} |
240
|
|
|
} |
241
|
|
|
} |
242
|
|
|
} |
243
|
|
|
field_players { |
244
|
|
|
path { |
245
|
|
|
alias |
246
|
|
|
} |
247
|
|
|
field_shirtnumber |
248
|
|
|
field_lastname |
249
|
|
|
field_firstname |
250
|
|
|
field_position |
251
|
|
|
relationships { |
252
|
|
|
field_image { |
253
|
|
|
localFile { |
254
|
|
|
...KCVVFluidPlayerTeaser |
255
|
|
|
} |
256
|
|
|
} |
257
|
|
|
} |
258
|
|
|
} |
259
|
|
|
field_media_article_image { |
260
|
|
|
...ArticleImage |
261
|
|
|
field_media_image { |
262
|
|
|
alt |
263
|
|
|
} |
264
|
|
|
} |
265
|
|
|
} |
266
|
|
|
} |
267
|
|
|
} |
268
|
|
|
` |
269
|
|
|
|
270
|
|
|
export default TeamTemplate |
271
|
|
|
|