Skip to content

Commit

Permalink
added components to app
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieWesolowska committed May 17, 2023
1 parent 3f8a70f commit 6690560
Show file tree
Hide file tree
Showing 5 changed files with 42 additions and 7 deletions.
37 changes: 33 additions & 4 deletions src/components/App.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,31 +11,60 @@ export class App extends Component {
bad: 0,
};

handleFeedback = e => {
if (e === 'Good') {
this.setState({ good: this.state.good + 1 });
} else if (e === 'Neutral') {
this.setState({ neutral: this.state.neutral + 1 });
} else if (e === 'Bad') {
this.setState({ bad: this.state.bad + 1 });
}
};

countTotalFeedback = () => {
let total = this.state.good + this.state.neutral + this.state.bad;
return total;
};

countPositiveFeedbackPercentage = () => {};
countPositiveFeedbackPercentage = () => {
if (this.countTotalFeedback() === 0) {
return 0;
}
return Math.round((this.state.good / this.countTotalFeedback()) * 100);
};

render() {
return (
<div
style={{
height: '100vh',
display: 'flex',
flexDirection: 'column',
justifyContent: 'center',
alignItems: 'center',
fontSize: 40,
color: '#010101',
}}
>
<SectionTitle title="Please leave feedback">
<FeedbackOptions />
<FeedbackOptions
options={['Good', 'Neutral', 'Bad']}
onLeaveFeedback={this.handleFeedback}
/>{' '}
</SectionTitle>

<SectionTitle title="Statistics">
<Statistics />
<Notification />
{this.countTotalFeedback() !== 0 ? (
<Statistics
good={this.state.good}
neutral={this.state.neutral}
bad={this.state.bad}
total={this.countTotalFeedback()}
positivePercentage={this.countPositiveFeedbackPercentage()}
/>
) : (
<Notification message="There is no feedback" />
)}
</SectionTitle>
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/FeedbackOptions/FeedbackOptions.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ import css from './FeedbackOptions.module.css';
import { nanoid } from 'nanoid';

export const FeedbackOptions = ({ options, onLeaveFeedback }) => (
<div>
<div className={css.feedContainer}>
{options.map(option => (
<button
key={nanoid()}
Expand Down
6 changes: 6 additions & 0 deletions src/components/FeedbackOptions/FeedbackOptions.module.css
Original file line number Diff line number Diff line change
@@ -1,3 +1,9 @@
.feedContainer {
display: flex;
justify-content: center;
gap: 30px;
}

.feedbackBtn {
.search-btn {
color: #fff;
Expand Down
2 changes: 1 addition & 1 deletion src/components/SectionTitle/SectionTitle.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ import propTypes from 'prop-types';

export const SectionTitle = ({ title, children }) => (
<div>
<h2>{title}</h2>
<h2 className={CSS.title}>{title}</h2>
{children}
</div>
);
Expand Down
2 changes: 1 addition & 1 deletion src/components/Statistics/Statistics.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ export const Statistics = ({
<li>Neutral: {neutral}</li>
<li>Bad: {bad}</li>
<li>Total: {total}</li>
<li>Positive feedback: {positivePercentage}</li>
<li>Positive feedback: {positivePercentage} %</li>
</ul>
);

Expand Down

0 comments on commit 6690560

Please sign in to comment.