Passed
Pull Request — develop (#758)
by Kevin Van
08:51 queued 04:39
created

src/pages/index.tsx   A

Complexity

Total Complexity 14
Complexity/F 0

Size

Lines of Code 342
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 14
eloc 174
mnd 14
bc 14
fnc 0
dl 0
loc 342
rs 10
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
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">THE A Team</header>
216
            <MatchesTabs teamId={1} />
217
          </article>
218
          <article className="frontpage__matches_carousel_item frontpage__matches_carousel_item--b">
219
            <header className="frontpage__matches_carousel_item__header">THE B Team</header>
220
            <MatchesTabs teamId={2} />
221
          </article>
222
        </main>
223
        <footer className="frontpage__matches_carousel__buttons">
224
          <span className="nav-btn prev" onClick={previousMatches}></span>
225
          <span className="nav-btn next" onClick={nextMatches}></span>
226
        </footer>
227
      </section>
228
229
      <section className="frontpage__main_content page__section">
230
        {featuredEvent.length > 0 && (
231
          <EventCard
232
            title={featuredEvent[0].node.title}
233
            picture={
234
              featuredEvent[0].node.relationships.field_media_image.relationships.field_media_image.localFile
235
                .childImageSharp.gatsbyImageData
236
            }
237
            link={featuredEvent[0].node.field_event_link.uri}
238
            datetimeStart={featuredEvent[0].node.field_daterange.value}
239
            datetimeEnd={featuredEvent[0].node.field_daterange.end_value}
240
          />
241
        )}
242
        {articles.edges.slice(0, featuredEvent.length > 0 ? 2 : 4).map(({ node }) => (
243
          <CardTeaser
244
            key={node.id}
245
            title={node.title}
246
            picture={
247
              node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
248
                .gatsbyImageData
249
            }
250
            link={node.path.alias}
251
            tags={node.relationships?.field_tags}
252
            createTime={node.created}
253
          />
254
        ))}
255
256
        <article className="frontpage__main_content__youth">
257
          <header className="frontpage__matches_carousel_item__header">Wedstrijden</header>
258
          <MatchesOverview exclude={[`1`, `2`]} action="next" />
259
        </article>
260
      </section>
261
262
      <section className="frontpage__kcvvtv page__section">
263
        {/* <AltTitle title="KCVV TV" variant="black" /> */}
264
        <div className="frontpage__kcvvtv__content">
265
          {videos.edges.map(({ node }, i) => (
266
            <CardTVTeaser
267
              key={i}
268
              title={node.title}
269
              picture={
270
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
271
                  .gatsbyImageData
272
              }
273
              link={node.field_website.uri}
274
              createTime={node.created}
275
            />
276
          ))}
277
        </div>
278
      </section>
279
280
      <div className="frontpage__advertisement">
281
        <StaticImage
282
          src="../images/cometogether.jpg"
283
          alt="#ComeTogether"
284
          className="frontpage__advertisement"
285
          width={960}
286
        />
287
      </div>
288
289
      <div className="frontpage__main_content__wrapper">
290
        <section className="frontpage__main_content page__section">
291
          {articles.edges.slice(featuredEvent.length > 0 ? 2 : 4, featuredEvent.length > 0 ? 8 : 10).map(({ node }) => (
292
            <CardTeaser
293
              key={node.id}
294
              title={node.title}
295
              picture={
296
                node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
297
                  .gatsbyImageData
298
              }
299
              link={node.path.alias}
300
              tags={node.relationships?.field_tags}
301
              createTime={node.created}
302
            />
303
          ))}
304
        </section>
305
      </div>
306
307
      <section className="frontpage__matches_slider page__section">
308
        <MatchesSlider />
309
      </section>
310
311
      <div className="frontpage__advertisement">
312
        <a href="mailto:[email protected]" target="_blank">
313
          <StaticImage
314
            src="../images/sponsoring.jpg"
315
            alt="Sponsor worden van KCVV?"
316
            className="frontpage__advertisement"
317
            width={960}
318
          />
319
        </a>
320
      </div>
321
    </Layout>
322
  )
323
}
324
325
const previousMatches = () => {
326
  const gallery = document.querySelector(`#frontpage__matches_carousel`)
327
  const gallery_scroller = gallery?.querySelector(`.frontpage__matches_carousel__content`)
328
  const gallery_item_size = gallery_scroller?.querySelector(`article`)?.clientWidth || 0
329
330
  gallery_scroller?.scrollBy(-gallery_item_size, 0)
331
}
332
333
const nextMatches = () => {
334
  const gallery = document.querySelector(`#frontpage__matches_carousel`)
335
  const gallery_scroller = gallery?.querySelector(`.frontpage__matches_carousel__content`)
336
  const gallery_item_size = gallery_scroller?.querySelector(`article`)?.clientWidth || 0
337
338
  gallery_scroller?.scrollBy(gallery_item_size, 0)
339
}
340
341
export default IndexPage
342