overkill with custom component

This commit is contained in:
Pablo Martin 2025-05-20 16:54:36 +02:00
parent 9c6404421a
commit 3044bd625f
3 changed files with 27 additions and 1 deletions

View file

@ -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,
}, },
], ],
}; };

View file

@ -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>
) )
} }

View 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;