training.js 1.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. function calculateRating (ratings) {
  2. const numberOfRatings = ratings.length
  3. const sumOfRatings = ratings.reduce(
  4. (accumulator, rating) => accumulator + rating.value,
  5. 0
  6. )
  7. console.log(ratings, sumOfRatings, numberOfRatings)
  8. return sumOfRatings / numberOfRatings
  9. }
  10. const TrainingArchive = props => (
  11. <div>
  12. <h2>Training Archive</h2>
  13. {console.log('archive', props)}
  14. <ol>
  15. {props.trainings.map(training => (
  16. <TrainingHint key={training.id} training={training} />
  17. ))}
  18. </ol>
  19. </div>
  20. )
  21. const TrainingHint = props => (
  22. <div>
  23. <div>{props.training.date}</div>
  24. <div>{props.training.title}</div>
  25. </div>
  26. )
  27. const Training = props => (
  28. <div>
  29. <h3>{props.training.title}</h3>
  30. <p>Date: {props.training.date}</p>
  31. <p>Location: {props.training.location}</p>
  32. <p>Participants: {props.training.participants.length}</p>
  33. <p>Rating: {calculateRating(props.training.ratings)}</p>
  34. <p>Content</p>
  35. </div>
  36. )
  37. export { TrainingArchive }
  38. export default Training