training.js 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. import theme from '../styles/theme'
  2. import TrainingBlock from './trainingBlock'
  3. function calculateRating (ratings) {
  4. const numberOfRatings = ratings.length
  5. const sumOfRatings = ratings.reduce(
  6. (accumulator, rating) => accumulator + rating.value,
  7. 0
  8. )
  9. return numberOfRatings ? sumOfRatings / numberOfRatings : '-'
  10. }
  11. const Training = props => (
  12. <article>
  13. <h2>{props.title}</h2>
  14. <aside>
  15. <div id='trainingType'>
  16. <span className='caption'>Type: </span>
  17. <span className='data'>{props.type.name}</span>
  18. </div>
  19. <div id='trainingDate'>
  20. <span className='caption'>Date: </span>
  21. <span className='data'>
  22. {new Date(props.trainingDate).toLocaleDateString()}
  23. </span>
  24. </div>
  25. <div id='trainingLocation'>
  26. <span className='caption'>Location: </span>
  27. <span className='data'>{props.location}</span>
  28. </div>
  29. <div id='trainingRegistrations'>
  30. <span className='caption'>Registrations: </span>
  31. <span className='data'> {props.registration.length} </span>
  32. </div>
  33. <div id='trainingAttendance'>
  34. <span className='caption'>Attendance: </span>
  35. <span className='data'>{props.attendance}</span>
  36. </div>
  37. <div id='trainingRatings'>
  38. <span className='caption'>Rating: </span>
  39. <span className='data'>
  40. {calculateRating(props.ratings)} [
  41. <a href=''>{props.ratings.length}</a>] Rate it!
  42. <a href=''>*</a>
  43. <a href=''>*</a>
  44. <a href=''>*</a>
  45. <a href=''>*</a>
  46. <a href=''>*</a>
  47. </span>
  48. </div>
  49. <button>Register now!</button>
  50. </aside>
  51. <section>
  52. <h3>Content</h3>
  53. <ol>
  54. {props.content
  55. .sort(block => block.sequence)
  56. .map(block => (
  57. <TrainingBlock key={block.id} {...block} />
  58. ))}
  59. </ol>
  60. </section>
  61. <style jsx>
  62. {`
  63. article {
  64. display: grid;
  65. grid-template-areas:
  66. 'title title'
  67. 'information placeholder'
  68. 'content content';
  69. grid-template-columns: 1fr 2fr;
  70. background-color: rgba(127, 127, 127, 0.5);
  71. background-image: url('media/man_working_out.jpg');
  72. background-size: auto 400px;
  73. background-repeat: no-repeat;
  74. margin: 2em 0;
  75. }
  76. article > * {
  77. padding: 0.2em 1em;
  78. }
  79. article > h2 {
  80. grid-area: title;
  81. font-weight: 900;
  82. font-size: 120%;
  83. background: ${theme.colors.darkerblue};
  84. color: ${theme.colors.offWhite};
  85. }
  86. aside {
  87. grid-area: information;
  88. background: rgba(0, 127, 0, 0.5);
  89. padding: 1em 2em;
  90. margin: 0 1em;
  91. min-height: 350px;
  92. }
  93. section {
  94. grid-area: content;
  95. padding: 1em 2em;
  96. background: rgba(127, 0, 0, 0.5);
  97. }
  98. span.caption {
  99. display: none;
  100. }
  101. `}
  102. </style>
  103. </article>
  104. )
  105. export default Training