-
Notifications
You must be signed in to change notification settings - Fork 0
/
App.js
58 lines (52 loc) · 1.58 KB
/
App.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
import React, { Component } from "react";
import Statistics from "./components/Statistics/Statistics";
import FeedbackOptions from "./components/FeedbackOptions/FeedbackOptions";
import Section from "./components/Section/Section";
import Notification from "./components/Notification/Notification";
import "./index.css";
class App extends Component {
state = {
good: 0,
neutral: 0,
bad: 0,
};
handleFeedback = (e) => {
const { name } = e.target;
this.setState((state) => ({ [name]: state[name] + 1 }));
};
countTotalFeedback = () => {
const { good, neutral, bad } = this.state;
return good + neutral + bad;
};
countPositiveFeedbackPercentage = () => {
const { good, neutral, bad } = this.state;
return Math.round((good / (good + neutral + bad)) * 100);
};
render() {
const { good, neutral, bad } = this.state;
const actualState = this.state;
const total = this.countTotalFeedback();
const positivePercentage = this.countPositiveFeedbackPercentage();
return (
<>
<Section title="Please leave feedback">
<FeedbackOptions options={actualState} onLeaveFeedback={this.handleFeedback} />
</Section>
<Section title="Statistics">
{total ? (
<Statistics
good={good}
neutral={neutral}
bad={bad}
total={total}
positivePercentage={positivePercentage}
/>
) : (
<Notification message="There is no feedback" />
)}
</Section>
</>
);
}
}
export default App;