Completed
Push — master ( 1b782b...279c80 )
by Stefan
02:36
created

src/Report.js   A

Complexity

Total Complexity 5
Complexity/F 1.67

Size

Lines of Code 54
Function Count 3

Duplication

Duplicated Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
wmc 5
eloc 42
mnd 2
bc 2
fnc 3
dl 0
loc 54
rs 10
bpm 0.6666
cpm 1.6666
noi 0
c 0
b 0
f 0
1
import React, {Component} from 'react';
2
import {Link} from "react-router-dom";
3
import auth from "./auth.js";
4
5
class Report extends Component {
6
7
    constructor() {
8
        super();
9
        this.state = {
10
            data: null,
11
            number: null
12
        };
13
    }
14
15
    componentDidMount() {
16
        // console.log(this.props);
17
        fetch("https://me-api.listrom.me/reports/week/" + this.props.match.params.number)
18
            .then(response => response.json())
19
            .then(data => {
20
                this.setState({ data: data.data.text});
21
                // console.log(this.state.data);
22
            });
23
    };
24
25
    componentDidUpdate(prevProps) {
26
        if(prevProps.match.params.number !== this.props.match.params.number) {
27
            fetch("https://me-api.listrom.me/reports/week/" + this.props.match.params.number)
28
                .then(response => response.json())
29
                .then(data => {
30
                    this.setState({ data: data.data.text});
31
                    // console.log(this.state.data);
32
                });
33
        }
34
    }
35
36
    render() {
37
        // console.log(this.props);
38
        let editUrl;
39
40
        if (auth.token !== "") {
41
            editUrl = <Link className='button' to={`/reports/edit/${this.props.match.params.number}`}>Edit</Link>;
42
        }
43
44
        return (
45
            <main>
46
                <h3>Kmom {this.props.match.params.number}</h3>
47
                <p>{editUrl}</p>
48
                <article dangerouslySetInnerHTML={{__html: this.state.data}}></article>
49
            </main>
50
        );
51
    }
52
}
53
54
export default Report;