Passed
Push — renovate/major-gatsby-monorepo ( a0865d...366838 )
by
unknown
03:18
created

src/templates/team.js   A

Complexity

Total Complexity 1
Complexity/F 0

Size

Lines of Code 334
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 228
mnd 1
bc 1
fnc 0
dl 0
loc 334
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { graphql } from "gatsby"
2
import React 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 Ranking from "../components/ranking"
9
import TeamCalendarMatches from "../components/team-calendar-matches"
10
import TeamCalendarMetaMatches from "../components/team-calendar-meta-matches"
11
12
// Generic helper function to group an array by a property.
13
const groupBy = (key) => (array) =>
14
  array.reduce((objectsByKeyValue, obj) => {
15
    const value = obj[key]
16
    objectsByKeyValue[value] = (objectsByKeyValue[value] || []).concat(obj)
17
    return objectsByKeyValue
18
  }, {})
19
20
// Specific implementation of our groupBy function, to group by a property "field_position".
21
const groupByPosition = groupBy("field_position")
22
23
export default ({ data }) => {
24
  const node = data.nodeTeam
25
26
  // If we have players, group them by their position.
27
  const playersByPosition =
28
    node.relationships.field_players.length > 0 &&
29
    groupByPosition(node.relationships.field_players)
30
31
  const picture = node.relationships.field_media_article_image
32
  // Create a fluid/responsive team image instance.
33
  const teamPicture = picture && (
34
    <Img
35
      fluid={
36
        picture.relationships.field_media_image.localFile.childImageSharp.fluid
37
      }
38
      alt={picture.field_media_image.alt}
39
      className={"team-detail__team-picture"}
40
    />
41
  )
42
43
  // Helper variable so we don't have to do the check over and over again.
44
  const hasDivision = node.field_fb_id || node.field_fb_id_2
45
46
  const pathUrl = node.path.alias
47
  const ogImage = picture && {
48
    src:
49
      node.relationships.field_media_article_image.relationships
50
        .field_media_image.localFile.childImageSharp.resize.src,
51
    width:
52
      node.relationships.field_media_article_image.relationships
53
        .field_media_image.localFile.childImageSharp.resize.width,
54
    height:
55
      node.relationships.field_media_article_image.relationships
56
        .field_media_image.localFile.childImageSharp.resize.height,
57
  }
58
59
  return (
60
    <Layout>
61
      <SEO
62
        lang="nl-BE"
63
        title={node.title + " / " + node.field_division_full}
64
        description={"KCVV Elewijt " + node.field_division_full}
65
        path={pathUrl}
66
        image={ogImage || null}
67
      />
68
69
      <article className={"team-detail"}>
70
        <header className={"team-detail__header"}>
71
          <h1 className={"team-detail__name"}>
72
            {/* > GEWESTELIJKE U13 K */}
73
            <span className={"team-detail__name-division"}>
74
              {node.field_division_full}
75
            </span>
76
            {/* > The A-team */}
77
            <span className={"team-detail__name-tagline"}>
78
              {node.field_tagline}
79
            </span>
80
          </h1>
81
82
          <div className={"bg-green-mask"}>
83
            <div className={"bg-white-end"} />
84
          </div>
85
86
          {/* > 2A, 2G9K... */}
87
          {/* 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) */}
88
          {hasDivision && (
89
            <div className={"team-detail__division-number"} aria-hidden="true">
90
              {node.field_fb_id_2 ? node.field_fb_id_2 : node.field_fb_id}
91
            </div>
92
          )}
93
        </header>
94
95
        <div className={"team-break"}></div>
96
97
        {/* 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 */}
98
        {(playersByPosition || hasDivision) && (
99
          <section className={"team-sub_navigation"}>
100
            {/* Foundation tabs structure */}
101
            <ul
102
              className={"tabs team-sub_navigation__tabs "}
103
              data-tabs
104
              data-deep-link="true"
105
              data-update-history="true"
106
              data-deep-link-smudge="true"
107
              data-deep-link-smudge-delay="500"
108
              id="team-subnavigation_tabs"
109
            >
110
              <li className="tabs-title is-active">
111
                <a href="#team-info">Info</a>
112
              </li>
113
              {/* Youth teams don't have lineups, so we don't show the tab link. */}
114
              {playersByPosition && (
115
                <li className="tabs-title">
116
                  <a href="#team-lineup">Lineup</a>
117
                </li>
118
              )}
119
              {hasDivision && (
120
                <>
121
                  <li className={"tabs-title"}>
122
                    <a data-tabs-target="team-matches" href="#team-matches">
123
                      Wedstrijden
124
                    </a>
125
                  </li>
126
                  <li className={"tabs-title"}>
127
                    <a data-tabs-target="team-ranking" href="#team-ranking">
128
                      Stand
129
                    </a>
130
                  </li>
131
                </>
132
              )}
133
            </ul>
134
          </section>
135
        )}
136
137
        {/* Foundation content of the tabs. */}
138
        <div
139
          className={"tabs-content"}
140
          data-tabs-content="team-subnavigation_tabs"
141
        >
142
          <div className={"tabs-panel is-active"} id="team-info">
143
            {teamPicture || ""}
144
            {node.field_contact_info && (
145
              <div
146
                className={"team-detail__team-info"}
147
                dangerouslySetInnerHTML={{
148
                  __html: node.field_contact_info.processed,
149
                }}
150
              />
151
            )}
152
          </div>
153
          {/* If our page displays staff only (e.g. the "board" page), we change the title. */}
154
          {node.relationships.field_staff && !playersByPosition && (
155
            <main
156
              className={"team-detail__lineup team-detail__lineup--staff-only"}
157
            >
158
              <TeamSection
159
                title="Stafleden"
160
                lineup={node.relationships.field_staff}
161
              />
162
            </main>
163
          )}
164
          {playersByPosition && (
165
            <div className={"tabs-panel"} id="team-lineup">
166
              <main className={"team-detail__lineup"}>
167
                {node.relationships.field_staff && (
168
                  <TeamSection
169
                    title="Stafleden"
170
                    lineup={node.relationships.field_staff}
171
                  />
172
                )}
173
                {playersByPosition["k"] && (
174
                  <TeamSection
175
                    title="Doelmannen"
176
                    lineup={playersByPosition["k"]}
177
                  />
178
                )}
179
                {playersByPosition["d"] && (
180
                  <TeamSection
181
                    title="Verdedigers"
182
                    lineup={playersByPosition["d"]}
183
                  />
184
                )}
185
                {playersByPosition["m"] && (
186
                  <TeamSection
187
                    title="Middenvelder"
188
                    lineup={playersByPosition["m"]}
189
                  />
190
                )}
191
                {playersByPosition["a"] && (
192
                  <TeamSection
193
                    title="Aanvallers"
194
                    lineup={playersByPosition["a"]}
195
                  />
196
                )}
197
              </main>
198
            </div>
199
          )}
200
          {hasDivision && (
201
            <>
202
              <div className={"tabs-panel"} id="team-matches">
203
                {node.field_fb_id_2 && (
204
                  <div className={"team-ranking__wrapper"}>
205
                    {node.field_fb_id && <h2>Wedstrijden na nieuwjaar</h2>}
206
207
                    {/* Metamatches is the big banner on top with the previous and next match highlighted. */}
208
                    {!node.field_fb_id && (
209
                      <TeamCalendarMetaMatches
210
                        season="1920"
211
                        region="bra"
212
                        division={node.field_fb_id_2}
213
                        regnumber="00055"
214
                      />
215
                    )}
216
217
                    <TeamCalendarMatches
218
                      season="1920"
219
                      region="bra"
220
                      division={node.field_fb_id_2}
221
                    />
222
                  </div>
223
                )}
224
                {node.field_fb_id && (
225
                  <div className={"team-ranking__wrapper"}>
226
                    {node.field_fb_id_2 && <h2>Wedstrijden voor nieuwjaar</h2>}
227
228
                    {/* Metamatches is the big banner on top with the previous and next match highlighted. */}
229
                    {!node.field_fb_id_2 && (
230
                      <TeamCalendarMetaMatches
231
                        season="1920"
232
                        region="bra"
233
                        division={node.field_fb_id}
234
                        regnumber="00055"
235
                      />
236
                    )}
237
238
                    <TeamCalendarMatches
239
                      season="1920"
240
                      region="bra"
241
                      division={node.field_fb_id}
242
                    />
243
                  </div>
244
                )}
245
              </div>
246
              <div className={"tabs-panel"} id="team-ranking">
247
                {node.field_fb_id_2 && (
248
                  <div className={"team-ranking__wrapper"}>
249
                    {node.field_fb_id && <h2>Ranking na nieuwjaar</h2>}
250
                    <Ranking
251
                      season="1920"
252
                      region="bra"
253
                      division={node.field_fb_id_2}
254
                      highlight="KCVV.Elewijt A"
255
                    />
256
                  </div>
257
                )}
258
                {node.field_fb_id && (
259
                  <div className={"team-ranking__wrapper"}>
260
                    {node.field_fb_id_2 && <h2>Ranking voor nieuwjaar</h2>}
261
                    <Ranking
262
                      season="1920"
263
                      region="bra"
264
                      division={node.field_fb_id}
265
                      highlight="KCVV.Elewijt A"
266
                    />
267
                  </div>
268
                )}
269
              </div>
270
            </>
271
          )}
272
        </div>
273
      </article>
274
    </Layout>
275
  )
276
}
277
278
export const query = graphql`
279
  query($slug: String!) {
280
    nodeTeam(path: { alias: { eq: $slug } }) {
281
      path {
282
        alias
283
      }
284
      title
285
      field_contact_info {
286
        processed
287
      }
288
      field_fb_id
289
      field_fb_id_2
290
      field_division_full
291
      field_tagline
292
      relationships {
293
        field_staff {
294
          path {
295
            alias
296
          }
297
          field_position_short
298
          field_lastname
299
          field_firstname
300
          relationships {
301
            field_image {
302
              localFile {
303
                ...KCVVFluidPlayerTeaser
304
              }
305
            }
306
          }
307
        }
308
        field_players {
309
          path {
310
            alias
311
          }
312
          field_shirtnumber
313
          field_lastname
314
          field_firstname
315
          field_position
316
          relationships {
317
            field_image {
318
              localFile {
319
                ...KCVVFluidPlayerTeaser
320
              }
321
            }
322
          }
323
        }
324
        field_media_article_image {
325
          ...ArticleImage
326
          field_media_image {
327
            alt
328
          }
329
        }
330
      }
331
    }
332
  }
333
`
334