Passed
Push — master ( 7aa1e4...a37cc0 )
by Kevin Van
05:30
created

src/pages/index.tsx   A

Complexity

Total Complexity 14
Complexity/F 0

Size

Lines of Code 346
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 178
mnd 14
bc 14
fnc 0
dl 0
loc 346
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { graphql, Link, useStaticQuery } from "gatsby"
2
import { GatsbyImage, StaticImage } from "gatsby-plugin-image"
3
import React from "react"
4
5
import { HomepageResponsePropsApi } from "../Types/Gatsby"
6
import { AltTitle } from "../components/AltTitle"
7
import { CardTeaser, CardTVTeaser } from "../components/Card"
8
import { MatchesOverview } from "../components/MatchesOverview"
9
import MatchesSlider from "../components/MatchesSlider"
10
import { MatchesTabs } from "../components/MatchesTabs"
11
import { Seo } from "../components/Seo"
12
import Layout from "../layouts"
13
import "./index.scss"
14
import EventCard from "../components/EventCard"
15
import classnames from "classnames"
16
import Icon from "../components/Icon"
17
18
export const Head = () => (
19
  <Seo
20
    title="Er is maar één plezante compagnie"
21
    description="Startpagina van stamnummer 00055: KCVV Elewijt."
22
    path={`/`}
23
    keywords={[`KCVV`, `Voetbal`, `Elewijt`, `Crossing`, `KCVVE`, `Zemst`, `00055`, `55`, `1982`, `1980`]}
24
  />
25
)
26
27
const IndexPage = () => {
28
  const { articles, videos, events, stickyArticles }: HomepageResponsePropsApi = useStaticQuery(graphql`
29
    query {
30
      articles: allNodeArticle(
31
        filter: { status: { eq: true }, promote: { eq: true } }
32
        sort: { fields: created, order: DESC }
33
        limit: 10
34
      ) {
35
        edges {
36
          node {
37
            id
38
            path {
39
              alias
40
            }
41
            created(formatString: "D/M/YYYY")
42
            changed(formatString: "D/M/YYYY")
43
            timestamp: changed(formatString: "x")
44
            title
45
            promote
46
            status
47
            field_featured
48
            body {
49
              value
50
              format
51
              processed
52
              summary
53
            }
54
            relationships {
55
              field_media_article_image {
56
                ...ArticleImage
57
              }
58
              field_tags {
59
                name
60
                path {
61
                  alias
62
                }
63
              }
64
            }
65
            internal {
66
              type
67
            }
68
          }
69
        }
70
      }
71
      stickyArticles: allNodeArticle(
72
        filter: { status: { eq: true }, promote: { eq: true }, sticky: { eq: true } }
73
        sort: { fields: created, order: DESC }
74
        limit: 3
75
      ) {
76
        edges {
77
          node {
78
            id
79
            path {
80
              alias
81
            }
82
            created(formatString: "D/M/YYYY")
83
            changed(formatString: "D/M/YYYY")
84
            timestamp: changed(formatString: "x")
85
            title
86
            promote
87
            status
88
            field_featured
89
            body {
90
              value
91
              format
92
              processed
93
              summary
94
            }
95
            relationships {
96
              field_media_article_image {
97
                ...ArticleImageLarge
98
              }
99
              field_tags {
100
                name
101
                path {
102
                  alias
103
                }
104
              }
105
            }
106
            internal {
107
              type
108
            }
109
          }
110
        }
111
      }
112
      videos: allNodeKcvvTv(
113
        filter: { status: { eq: true }, promote: { eq: true } }
114
        sort: { fields: created, order: DESC }
115
        limit: 3
116
      ) {
117
        edges {
118
          node {
119
            created(formatString: "D/M/YYYY")
120
            title
121
            timestamp: created(formatString: "x")
122
            relationships {
123
              field_media_article_image {
124
                ...ArticleImage
125
              }
126
            }
127
            field_website {
128
              uri
129
            }
130
          }
131
        }
132
      }
133
      events: allNodeEvent(
134
        filter: { promote: { eq: true }, status: { eq: true } }
135
        sort: { order: ASC, fields: field_daterange___value }
136
        limit: 1
137
      ) {
138
        edges {
139
          node {
140
            field_daterange {
141
              value(formatString: "YYYY-MM-DDTHH:mm:ssZ")
142
              end_value(formatString: "YYYY-MM-DDTHH:mm:ssZ")
143
            }
144
            field_event_link {
145
              uri
146
            }
147
            title
148
            relationships {
149
              field_media_image {
150
                field_media_image {
151
                  alt
152
                }
153
                relationships {
154
                  field_media_image {
155
                    localFile {
156
                      ...KCVVFluid960
157
                    }
158
                  }
159
                }
160
              }
161
            }
162
          }
163
        }
164
      }
165
    }
166
  `)
167
168
  const featuredEvent = events.edges.slice(0, 1)
169
170
  return (
171
    <Layout>
172
      <section className="frontpage__featured_articles">
173
        {stickyArticles.edges.map(({ node }, i) => (
174
          <Link
175
            key={`featured-${i}`}
176
            to={node.path.alias}
177
            className={classnames(`frontpage__featured_article`, { "frontpage__featured_article--active": i === 0 })}
178
          >
179
            <GatsbyImage
180
              image={
181
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
182
                  .gatsbyImageData
183
              }
184
              alt={node.title}
185
            />
186
            <div className="frontpage__featured_article__title__wrapper">
187
              <h3 className="frontpage__featured_article__title">{node.title}</h3>
188
              <div
189
                className="frontpage__featured_article__title__description"
190
                dangerouslySetInnerHTML={{ __html: node.body.summary }}
191
              />
192
              <div className="frontpage__featured_article__meta__wrapper">
193
                <div className="frontpage__featured_article__meta">
194
                  {node.relationships.field_tags && node.relationships.field_tags?.length > 0 && (
195
                    <div className={`frontpage__featured_article__meta__tags`}>
196
                      <Icon icon="fa-tags" />
197
                      {node.relationships.field_tags.map(({ name }, i) => (
198
                        <span className={`tag__label`} key={i}>
199
                          #{name}
200
                        </span>
201
                      ))}
202
                    </div>
203
                  )}
204
                </div>
205
              </div>
206
            </div>
207
          </Link>
208
        ))}
209
      </section>
210
211
      <section className="frontpage__matches_carousel page__section" id="frontpage__matches_carousel">
212
        {/* <AltTitle title="matches" variant="black" /> */}
213
        <main className="frontpage__matches_carousel__content">
214
          <article className="frontpage__matches_carousel_item frontpage__matches_carousel_item--a">
215
            <header className="frontpage__matches_carousel_item__header">
216
              <Link to="/team/a-ploeg">THE A Team &raquo;</Link>
217
            </header>
218
            <MatchesTabs teamId={1} />
219
          </article>
220
          <article className="frontpage__matches_carousel_item frontpage__matches_carousel_item--b">
221
            <header className="frontpage__matches_carousel_item__header">
222
              <Link to="/team/b-ploeg">THE B Team &raquo;</Link>
223
            </header>
224
            <MatchesTabs teamId={2} />
225
          </article>
226
        </main>
227
        <footer className="frontpage__matches_carousel__buttons">
228
          <span className="nav-btn prev" onClick={previousMatches}></span>
229
          <span className="nav-btn next" onClick={nextMatches}></span>
230
        </footer>
231
      </section>
232
233
      <section className="frontpage__main_content page__section">
234
        {featuredEvent.length > 0 && (
235
          <EventCard
236
            title={featuredEvent[0].node.title}
237
            picture={
238
              featuredEvent[0].node.relationships.field_media_image.relationships.field_media_image.localFile
239
                .childImageSharp.gatsbyImageData
240
            }
241
            link={featuredEvent[0].node.field_event_link.uri}
242
            datetimeStart={featuredEvent[0].node.field_daterange.value}
243
            datetimeEnd={featuredEvent[0].node.field_daterange.end_value}
244
          />
245
        )}
246
        {articles.edges.slice(0, featuredEvent.length > 0 ? 2 : 4).map(({ node }) => (
247
          <CardTeaser
248
            key={node.id}
249
            title={node.title}
250
            picture={
251
              node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
252
                .gatsbyImageData
253
            }
254
            link={node.path.alias}
255
            tags={node.relationships?.field_tags}
256
            createTime={node.created}
257
          />
258
        ))}
259
260
        <article className="frontpage__main_content__youth">
261
          <header className="frontpage__matches_carousel_item__header">Wedstrijden</header>
262
          <MatchesOverview exclude={[`1`, `2`]} action="next" />
263
        </article>
264
      </section>
265
266
      <section className="frontpage__kcvvtv page__section">
267
        {/* <AltTitle title="KCVV TV" variant="black" /> */}
268
        <div className="frontpage__kcvvtv__content">
269
          {videos.edges.map(({ node }, i) => (
270
            <CardTVTeaser
271
              key={i}
272
              title={node.title}
273
              picture={
274
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
275
                  .gatsbyImageData
276
              }
277
              link={node.field_website.uri}
278
              createTime={node.created}
279
            />
280
          ))}
281
        </div>
282
      </section>
283
284
      <div className="frontpage__advertisement">
285
        <StaticImage
286
          src="../images/cometogether.jpg"
287
          alt="#ComeTogether"
288
          className="frontpage__advertisement"
289
          width={960}
290
        />
291
      </div>
292
293
      <div className="frontpage__main_content__wrapper">
294
        <section className="frontpage__main_content page__section">
295
          {articles.edges.slice(featuredEvent.length > 0 ? 2 : 4, featuredEvent.length > 0 ? 8 : 10).map(({ node }) => (
296
            <CardTeaser
297
              key={node.id}
298
              title={node.title}
299
              picture={
300
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
301
                  .gatsbyImageData
302
              }
303
              link={node.path.alias}
304
              tags={node.relationships?.field_tags}
305
              createTime={node.created}
306
            />
307
          ))}
308
        </section>
309
      </div>
310
311
      <section className="frontpage__matches_slider page__section">
312
        <MatchesSlider />
313
      </section>
314
315
      <div className="frontpage__advertisement">
316
        <a href="mailto:[email protected]" target="_blank">
317
          <StaticImage
318
            src="../images/sponsoring.jpg"
319
            alt="Sponsor worden van KCVV?"
320
            className="frontpage__advertisement"
321
            width={960}
322
          />
323
        </a>
324
      </div>
325
    </Layout>
326
  )
327
}
328
329
const previousMatches = () => {
330
  const gallery = document.querySelector(`#frontpage__matches_carousel`)
331
  const gallery_scroller = gallery?.querySelector(`.frontpage__matches_carousel__content`)
332
  const gallery_item_size = gallery_scroller?.querySelector(`article`)?.clientWidth || 0
333
334
  gallery_scroller?.scrollBy(-gallery_item_size, 0)
335
}
336
337
const nextMatches = () => {
338
  const gallery = document.querySelector(`#frontpage__matches_carousel`)
339
  const gallery_scroller = gallery?.querySelector(`.frontpage__matches_carousel__content`)
340
  const gallery_item_size = gallery_scroller?.querySelector(`article`)?.clientWidth || 0
341
342
  gallery_scroller?.scrollBy(gallery_item_size, 0)
343
}
344
345
export default IndexPage
346