overkill with custom component
This commit is contained in:
parent
9c6404421a
commit
3044bd625f
3 changed files with 27 additions and 1 deletions
|
|
@ -18,7 +18,7 @@ const App = () => {
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
part: "An extra part I added just like that",
|
part: "An extra part I added just like that",
|
||||||
exerciseCount: 1,
|
exerciseCount: 3,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -1,11 +1,13 @@
|
||||||
import Header from "./Header";
|
import Header from "./Header";
|
||||||
import Content from "./Content";
|
import Content from "./Content";
|
||||||
|
import ExerciseCount from "./ExerciseCount";
|
||||||
|
|
||||||
const Course = ({course}) => {
|
const Course = ({course}) => {
|
||||||
return (
|
return (
|
||||||
<div>
|
<div>
|
||||||
<Header course={course.name} />
|
<Header course={course.name} />
|
||||||
<Content sections={course.sections} />
|
<Content sections={course.sections} />
|
||||||
|
<ExerciseCount sections={course.sections}/>
|
||||||
</div>
|
</div>
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
|
||||||
24
parts/2/courseExercise/src/components/ExerciseCount.jsx
Normal file
24
parts/2/courseExercise/src/components/ExerciseCount.jsx
Normal file
|
|
@ -0,0 +1,24 @@
|
||||||
|
import InflectedUnitNumber from "./InflectedUnitNumber";
|
||||||
|
|
||||||
|
const ExerciseCount = ({ sections }) => {
|
||||||
|
const exerciseCount = sections
|
||||||
|
.map((section) => section.exerciseCount)
|
||||||
|
.reduce((cumCount, sectionCount) => {
|
||||||
|
return cumCount + sectionCount;
|
||||||
|
}, 0);
|
||||||
|
|
||||||
|
return (
|
||||||
|
<p>
|
||||||
|
<b>
|
||||||
|
Total of{" "}
|
||||||
|
<InflectedUnitNumber
|
||||||
|
number={exerciseCount}
|
||||||
|
singular="exercise"
|
||||||
|
plural="exercises"
|
||||||
|
/>
|
||||||
|
</b>
|
||||||
|
</p>
|
||||||
|
);
|
||||||
|
};
|
||||||
|
|
||||||
|
export default ExerciseCount;
|
||||||
Loading…
Add table
Add a link
Reference in a new issue