Passed
Push — feature/netlify-search ( 939dfd...fbe251 )
by Kevin Van
05:37
created

src/components/MatchesSlider.tsx   A

Complexity

Total Complexity 1
Complexity/F 1

Size

Lines of Code 94
Function Count 1

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 1
eloc 67
mnd 0
bc 0
fnc 1
dl 0
loc 94
rs 10
bpm 0
cpm 1
noi 0
c 0
b 0
f 0

1 Function

Rating   Name   Duplication   Size   Complexity  
A MatchesSlider.tsx ➔ getData 0 3 1
1
import React, { FunctionComponent, useState } from "react"
2
3
import { graphql, useStaticQuery } from "gatsby"
4
import axios from "axios"
5
import "./MatchesSlider.scss"
6
7
import Slider, { LazyLoadTypes } from "react-slick"
8
import { useEffect } from "react"
9
import { MatchTeaserDetail } from "./MatchTeaser"
10
import Spinner from "./Spinner"
11
12
const MatchesSlider: FunctionComponent = () => {
13
  const [data, setData] = useState<Match[]>([])
14
15
  const {
16
    site: {
17
      siteMetadata: { kcvvPsdApi },
18
    },
19
  }: MatchesQueryData = useStaticQuery(graphql`
20
    {
21
      site {
22
        siteMetadata {
23
          kcvvPsdApi
24
        }
25
      }
26
    }
27
  `)
28
29
  const settings_slickslider = {
30
    slidesToShow: 4,
31
    slidesToScroll: 1,
32
    dots: false,
33
    arrows: true,
34
    centerMode: true,
35
    focusOnSelect: true,
36
    infinite: true,
37
    lazyLoad: `progressive` as LazyLoadTypes,
38
39
    responsive: [
40
      {
41
        breakpoint: 1700,
42
        settings: {
43
          slidesToShow: 4,
44
        },
45
      },
46
      {
47
        breakpoint: 1400,
48
        settings: {
49
          slidesToShow: 3,
50
        },
51
      },
52
      {
53
        breakpoint: 1200,
54
        settings: {
55
          slidesToShow: 2,
56
        },
57
      },
58
      {
59
        breakpoint: 800,
60
        settings: {
61
          slidesToShow: 1,
62
        },
63
      },
64
    ],
65
  }
66
67
  useEffect(() => {
68
    async function getData() {
69
      const response = await axios.get(`${kcvvPsdApi}/matches/next`)
70
      setData(response.data)
71
    }
72
    getData()
73
  }, [])
74
75
  return (
76
    <div className="matches_slider__wrapper">
77
      {data.length > 0 || <Spinner />}
78
      <Slider className={`matches_slider`} {...settings_slickslider}>
79
        {data
80
          .sort((a, b) => a.timestamp - b.timestamp)
81
          .map((match: Match, i) => {
82
            return (
83
              <div className="matches_slider__item" key={i} data-equalizer-watch="true">
84
                <MatchTeaserDetail match={match} />
85
              </div>
86
            )
87
          })}
88
      </Slider>
89
    </div>
90
  )
91
}
92
93
export default MatchesSlider
94