src/components/RelatedNews.tsx   A
last analyzed

Complexity

Total Complexity 16
Complexity/F 0

Size

Lines of Code 41
Function Count 0

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 16
eloc 32
mnd 16
bc 16
fnc 0
dl 0
loc 41
bpm 0
cpm 0
noi 0
c 0
b 0
f 0
rs 10
1
import React from "react"
2
import { RelatedNewsProps } from "../Types/News"
3
import { CardTeaser } from "./Card"
4
import "./RelatedNews.scss"
5
const RelatedNews = ({ items, limit = -1 }: RelatedNewsProps) => {
6
  if (limit <= 0) {
7
    limit = items.length
8
  }
9
10
  return (
11
    <section className="related_news__wrapper">
12
      {items.length > 0 && <h2 className="featured-border">Gerelateerde inhoud</h2>}
13
14
      <main className="related_news__items">
15
        {items
16
          .sort((a, b) => {
17
            if (a?.created && b?.created) {
18
              return +b.created - +a.created
19
            } else {
20
              return 0
21
            }
22
          })
23
          .splice(0, limit)
24
          .map((item, i) => {
25
            const picture =
26
              item?.relationships?.field_media_article_image?.relationships?.field_media_image?.localFile
27
                ?.childImageSharp?.gatsbyImageData || null
28
29
            return (
30
              picture && (
31
                <CardTeaser key={i} title={item?.title || ``} picture={picture} link={item?.path?.alias ?? ``} />
32
              )
33
            )
34
          })}
35
      </main>
36
    </section>
37
  )
38
}
39
40
export default RelatedNews
41