Passed
Pull Request — develop (#758)
by Kevin Van
04:28
created

srcBU/components/news-item.js   A

Complexity

Total Complexity 6
Complexity/F 1.2

Size

Lines of Code 98
Function Count 5

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 6
eloc 67
mnd 1
bc 1
fnc 5
dl 0
loc 98
rs 10
bpm 0.2
cpm 1.2
noi 0
c 0
b 0
f 0

5 Functions

Rating   Name   Duplication   Size   Complexity  
A NewsItemFeatured.render 0 5 1
A NewsItemSquare.render 0 5 1
A NewsItemCardRatio.render 0 12 2
A KcvvTvCard.render 0 14 1
A NewsItemCard.render 0 18 1
1
import { CardImage, CardTeaser, CardTeaserVertical } from "./Card"
2
import "./news-item.scss"
3
import React, { Component } from "react"
4
5
/**
6
 * Render a single news item in default card layout.
7
 */
8
export class NewsItemCard extends Component {
9
  render() {
10
    const { node, teaser = false } = this.props
11
    const localFile = node.relationships.field_media_article_image.relationships.field_media_image.localFile
12
    const summary = teaser && node.body.summary
13
14
    const relatedTags = node.relationships.field_tags || []
15
16
    return (
17
      <CardTeaser
18
        title={node.title}
19
        body={summary}
20
        picture={localFile}
21
        link={node.path.alias}
22
        metadata={true}
23
        tags={relatedTags}
24
        createTime={node.created}
25
        key={node.nid}
26
        className={`test`}
27
      />
28
    )
29
  }
30
}
31
32
/**
33
 * Render a single news item in image focus card layout.
34
 */
35
export class NewsItemFeatured extends Component {
36
  render() {
37
    const { node } = this.props
38
    const localFile = node.relationships.field_media_article_image.relationships.field_media_image.localFile
39
40
    return <CardImage title={node.title} picture={localFile} link={node.path.alias} />
41
  }
42
}
43
44
/**
45
 * Render a single news item in vertical image card layout.
46
 */
47
export class NewsItemSquare extends Component {
48
  render() {
49
    const { node } = this.props
50
    const localFile = node.relationships.field_media_article_image.relationships.field_media_image.localFile
51
52
    return <CardTeaserVertical title={node.title} picture={localFile} link={node.path.alias} />
53
  }
54
}
55
56
/**
57
 * Render news item in appropriate layout depending on the aspect ratio.
58
 */
59
export class NewsItemCardRatio extends Component {
60
  render() {
61
    const { node, teaser = false } = this.props
62
63
    const { gatsbyImageData: heroImage } =
64
      node.relationships.field_media_article_image.relationships.field_media_image.localFile.childImageSharp
65
66
    const aspectRatio = heroImage.width / heroImage.height
67
68
    if (aspectRatio >= 1) {
69
      return <NewsItemCard node={node} teaser={teaser} />
70
    } else {
71
      return <NewsItemSquare node={node} />
72
    }
73
  }
74
}
75
76
/**
77
 * Render a single KCVV TV item in default card layout.
78
 */
79
export class KcvvTvCard extends Component {
80
  render() {
81
    const { node } = this.props
82
    const localFile = node.relationships.field_media_article_image.relationships.field_media_image.localFile
83
    const summary = `${node.title}<br/><br/>Bekijk hier het wedstrijdverslag, interviews, nabespreking... en stem voor je man van de match!`
84
    return (
85
      <CardImage
86
        title={`KCVV TV`}
87
        icon={`fa-facebook-square`}
88
        body={summary}
89
        picture={localFile}
90
        link={node.field_website.uri}
91
        metadata={true}
92
        key={node.nid}
93
        createTime={node.created}
94
      />
95
    )
96
  }
97
}
98