Passed
Push — feature/inline-critical-css ( d54f1b )
by Kevin Van
05:27
created

src/components/match-with-logo.js   A

Complexity

Total Complexity 10
Complexity/F 1.43

Size

Lines of Code 144
Function Count 7

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 10
eloc 110
mnd 3
bc 3
fnc 7
dl 0
loc 144
rs 10
bpm 0.4285
cpm 1.4285
noi 0
c 0
b 0
f 0
1
import React, { Component } from "react"
2
import ClubLogo from "./clublogo"
3
import { mapMatchStatus, formatDivision } from "../scripts/helper"
4
import "./match-with-logo.scss"
5
import moment from "moment"
6
import "moment/locale/nl-be"
7
8
class MatchWithLogo extends Component {
9
  renderScoreWithWinnerIndicator = (result1, result2, extraClass) => {
10
    return result1 > result2 ? (
11
      <span
12
        className={`match-details__winner match-details__winner--${extraClass}`}
13
      >
14
        {result1}
15
      </span>
16
    ) : (
17
      <span className={"match-details__loser"}>{result1}</span>
18
    )
19
  }
20
  renderScore = (resultHome, resultAway) => {
21
    return typeof resultHome !== "undefined" &&
22
      typeof resultAway !== "undefined" ? (
23
      <div className={"match-details__vs match-details__vs--score"}>
24
        {this.renderScoreWithWinnerIndicator(resultHome, resultAway, "home")}
25
        <span className={"match-details__divider"}> - </span>
26
        {this.renderScoreWithWinnerIndicator(resultAway, resultHome, "away")}
27
      </div>
28
    ) : (
29
      <div className={"match-details__vs"}>VS</div>
30
    )
31
  }
32
33
  renderTeam = (regNumber, title, lazyload, extraClass) => {
34
    return (
35
      <div className={"match-details__lineup-inner"}>
36
        <ClubLogo
37
          regNumber={regNumber}
38
          title={title}
39
          className={`match-details__logo match-details__logo--${extraClass}`}
40
          lazyload={lazyload}
41
        />
42
        <div className={"match-details__teamname"}>{title}</div>
43
      </div>
44
    )
45
  }
46
47
  renderMatchWithStatusHeader = (matchTime, status) => {
48
    return (
49
      <>
50
        <time
51
          dateTime={matchTime.format("YYYY-MM-DD - H:mm")}
52
          className={"match-details__datetime match-details__datetime--date"}
53
        >
54
          {matchTime.format("dddd DD MMMM - H:mm")}
55
        </time>
56
        <div className={"match-details__status match-details__datetime--time"}>
57
          {mapMatchStatus(status)}
58
        </div>
59
      </>
60
    )
61
  }
62
63
  renderMatchWithoutStatusHeader = (matchTime) => {
64
    return (
65
      <>
66
        <time
67
          dateTime={matchTime.format("YYYY-MM-DD")}
68
          className={"match-details__datetime match-details__datetime--date"}
69
        >
70
          {matchTime.format("dddd DD MMMM YYYY")}
71
        </time>
72
        <time
73
          dateTime={matchTime.format("H:mm")}
74
          className={"match-details__datetime match-details__datetime--time"}
75
        >
76
          {matchTime.format("H:mm")}
77
        </time>
78
      </>
79
    )
80
  }
81
82
  renderMatchWithStatusHeader = (matchTime, status) => {
83
    return (
84
      <>
85
        <time
86
          dateTime={matchTime.format("YYYY-MM-DD - H:mm")}
87
          className={"match-details__datetime match-details__datetime--date"}
88
        >
89
          {matchTime.format("dddd DD MMMM - H:mm")}
90
        </time>
91
        <div className={"match-details__status match-details__datetime--time"}>
92
          {mapMatchStatus(status)}
93
        </div>
94
      </>
95
    )
96
  }
97
  render() {
98
    const {
99
      // season,
100
      region,
101
      division,
102
      dateTime,
103
      home,
104
      away,
105
      resultHome,
106
      resultAway,
107
      status,
108
      // matchDay,
109
      regNumberHome,
110
      regNumberAway,
111
    } = this.props.match
112
113
    moment.locale("nl-be")
114
115
    const lazyload = this.props.lazyload && true
116
117
    const matchTime = moment(dateTime)
118
119
    return (
120
      <article className={"match-details--with-logo match-details"}>
121
        <div className={"match-details__inner"}>
122
          <header>
123
            <h5>{formatDivision(division, region)}</h5>
124
125
            {status
126
              ? this.renderMatchWithStatusHeader(matchTime, status)
127
              : this.renderMatchWithoutStatusHeader(matchTime)}
128
          </header>
129
          <main>
130
            <section className={"match-details__lineup"}>
131
              {this.renderTeam(regNumberHome, home, lazyload, "home")}
132
              {this.renderScore(resultHome, resultAway)}
133
              {this.renderTeam(regNumberAway, away, lazyload, "away")}
134
            </section>
135
          </main>
136
          <footer />
137
        </div>
138
      </article>
139
    )
140
  }
141
}
142
143
export default MatchWithLogo
144