Passed
Push — feature/club-calendar ( fbac88 )
by Kevin Van
06:30
created

Calendar.tsx ➔ getData   A

Complexity

Conditions 1

Size

Total Lines 3
Code Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
eloc 3
dl 0
loc 3
c 0
b 0
f 0
rs 10
cc 1
1
import React, { FunctionComponent, useEffect, useState } from "react"
2
import { graphql, Link, useStaticQuery } from "gatsby"
3
4
import axios from "axios"
5
import LazyLoad from "react-lazyload"
6
import classNames from "classnames"
7
import Moment from "moment-timezone"
8
import "moment/locale/nl-be"
9
10
import { mapPsdStatus, mapPsdStatusIcon } from "../scripts/helper"
11
12
import "./Matches.scss"
13
import Icon from "./Icon"
14
import Spinner from "./Spinner"
15
16
const CalendarEvent: FunctionComponent<CalendarEventProps> = ({ event }: CalendarEventProps) => {
17
  const startDate = Moment.tz(event.start, `Europe/Brussels`)
18
  const endDate = Moment.tz(event.end, `Europe/Brussels`)
19
  const statusIcon = mapPsdStatusIcon(event.status)
20
21
  return (
22
    <article style={{ backgroundColor: event.color }}>
23
      <header className="calendar__title">
24
        <h3>
25
          <span className="calendar__date">
26
            {startDate.format(`dddd D MMM YYYY HH:mm`)} - {endDate.format(`HH:mm`)}
27
          </span>
28
          {/* <span className="matches__calendar__type">{match.competitionType}</span> */}
29
        </h3>
30
      </header>
31
      Type: {event.type}
32
      <br />
33
      Title: {event.title}
34
      <br />
35
      {statusIcon && <Icon icon={statusIcon} alt={mapPsdStatus(event.status) || ``} />}
36
      <br />
37
      Icon: {event.icon}
38
      <br />
39
      {event.repetition && <Icon icon={`fa-repeat`} alt={`Wederkerend evenement`} />}
40
      <br />
41
      All Day: {event.allDay && `YEP`}
42
      <br />
43
      Team IDs: {event.teamIds}
44
      <br />
45
      Team Names: {event.teamNames}
46
      <br />
47
      Cancelled: {event.cancelled && <Icon icon={`fa-times`} alt={`Afgelast`} />}
48
      <br />
49
      Meeting Location: {event.meetingLocation} - {event.meetingHour}
50
      <br />
51
      Description: <p dangerouslySetInnerHTML={{ __html: event.description || `` }} />
52
      Description 2: <p dangerouslySetInnerHTML={{ __html: event.fullDescription || `` }} />
53
    </article>
54
  )
55
}
56
57
const Calendar: FunctionComponent = () => {
58
  const [data, setData] = useState<CalendarEvent[]>([])
59
60
  const {
61
    site: {
62
      siteMetadata: { kcvvPsdApi },
63
    },
64
  }: CalendarQueryData = useStaticQuery(graphql`
65
    {
66
      site {
67
        siteMetadata {
68
          kcvvPsdApi
69
        }
70
      }
71
    }
72
  `)
73
74
  Moment.locale(`nl-BE`)
75
76
  useEffect(() => {
77
    async function getData() {
78
      const response = await axios.get(`${kcvvPsdApi}/events/next`)
79
      setData(response.data)
80
    }
81
    getData()
82
  }, [])
83
84
  return (
85
    <div className={`events__wrapper`}>
86
      {data.length > 0 || <Spinner />}
87
      <table>
88
        <thead>
89
          <tr>
90
            <th className={`table__column__number`}>#</th>
91
            <th className={`table__column__string`}>Team</th>
92
            <th className={`table__column__number show-for-medium`}>P</th>
93
            <th className={`table__column__number`}>W</th>
94
            <th className={`table__column__number`}>D</th>
95
            <th className={`table__column__number`}>L</th>
96
            <th className={`table__column__number show-for-medium`}>G+</th>
97
            <th className={`table__column__number show-for-medium`}>G-</th>
98
            <th className={`table__column__number`}>+/-</th>
99
            <th className={`table__column__number`}>Pts</th>
100
          </tr>
101
        </thead>
102
        <tbody>
103
          {data.map((event, i) => (
104
            <CalendarEvent event={event} key={i} />
105
          ))}
106
        </tbody>
107
      </table>
108
    </div>
109
  )
110
}
111
112
export default Calendar
113