Passed
Push — master ( 4fc8e9...0ebefa )
by Kevin Van
01:32 queued 12s
created

src/components/KcvvTvOverview.tsx   A

Complexity

Total Complexity 2
Complexity/F 0

Size

Lines of Code 111
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

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