Passed
Push — feature/kcvvtv-block ( 773bcf )
by Kevin Van
05:37
created

src/components/KcvvTvOverview.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 97
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 2
eloc 61
mnd 2
bc 2
fnc 0
dl 0
loc 97
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import { KcvvTv } from "../types/Drupal"
2
import Icon from "./Icon"
3
import "./KcvvTvOverview.scss"
4
import { KcvvTvEdge, KcvvTvOverviewQueryData } from "./KcvvTvOverview.types"
5
import { graphql, useStaticQuery } from "gatsby"
6
import { GatsbyImage, getImage } from "gatsby-plugin-image"
7
import React, { Fragment } from "react"
8
import { FunctionComponent } from "react"
9
10
const KcvvTvOverview: FunctionComponent = () => {
11
  const { videos }: KcvvTvOverviewQueryData = useStaticQuery(graphql`
12
    {
13
      videos: allNodeKcvvTv(
14
        filter: { status: { eq: true }, promote: { eq: true } }
15
        sort: { fields: created, order: DESC }
16
        limit: 5
17
      ) {
18
        edges {
19
          node {
20
            created(formatString: "D/M/YYYY")
21
            title
22
            timestamp: created(formatString: "x")
23
            relationships {
24
              field_media_article_image {
25
                ...ArticleImage
26
              }
27
            }
28
            field_website {
29
              uri
30
            }
31
          }
32
        }
33
      }
34
    }
35
  `)
36
37
  return (
38
    <section className="kcvvtv-wrapper">
39
      {videos && <KcvvTvFeatured node={videos.edges.slice(0, 1)[0].node} />}
40
      <div className="kcvvtv-list">
41
        {videos &&
42
          videos.edges.slice(1).map(({ node }, i) => {
43
            return <KcvvTvListItem key={i} node={node} />
44
          })}
45
      </div>
46
    </section>
47
  )
48
}
49
50
const KcvvTvFeatured: FunctionComponent<KcvvTvEdge> = ({ node }: KcvvTvEdge) => {
51
  const localFile =
52
    node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
53
      .gatsbyImageData
54
  const image = getImage(localFile)
55
56
  if (image) {
57
    return (
58
      <article className="kcvvtv-featured">
59
        <a href={node.field_website.url} title={`${node.title}: Speel video af via Facebook`}>
60
          <GatsbyImage image={image} alt={node.title} />
61
          <div className="gradient gradient--70"></div>
62
          <header className="kcvvtv__heading">
63
            <span className="kcvvtv__play" />
64
            <h3 className="kcvvtv__title">
65
              <Icon icon={`fa-facebook-square`} /> {node.title}
66
            </h3>
67
          </header>
68
        </a>
69
      </article>
70
    )
71
  } else {
72
    return <></>
73
  }
74
}
75
76
const KcvvTvListItem: FunctionComponent<KcvvTvEdge> = ({ node }: KcvvTvEdge) => {
77
  const localFile =
78
    node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
79
      .gatsbyImageData
80
  const image = getImage(localFile)
81
  if (image) {
82
    return (
83
      <article className="kcvvtv-list-item">
84
        <a href={node.field_website.url} title={`${node.title}: Speel video af via Facebook`}>
85
          <aside className="kcvvtv-teaser-image"><GatsbyImage image={image} alt={node.title} /><span className="kcvvtv__play" /></aside>
86
87
          <h4 className="kcvvtv__title">{node.title}</h4>
88
        </a>
89
      </article>
90
    )
91
  } else {
92
    return <></>
93
  }
94
}
95
96
export default KcvvTvOverview
97