training.js 3.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160
  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 numberOfRatings ? 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. <article>
  29. <h2>{props.title}</h2>
  30. <aside>
  31. <div id='trainingType'>
  32. <span className='caption'>Type: </span>
  33. <span className='data'>{props.type.name}</span>
  34. </div>
  35. <div id='trainingDate'>
  36. <span className='caption'>Date: </span>
  37. <date className='data'>
  38. {new Date(props.trainingDate).toLocaleDateString()}
  39. </date>
  40. </div>
  41. <div id='trainingLocation'>
  42. <span className='caption'>Location: </span>
  43. <span className='data'>{props.location}</span>
  44. </div>
  45. <div id='trainingRegistrations'>
  46. <span className='caption'>Registrations: </span>
  47. <span className='data'>
  48. {props.registration.length} <a href=''>Register!</a>
  49. </span>
  50. </div>
  51. <div id='trainingAttendance'>
  52. <span className='caption'>Attendance: </span>
  53. <span className='data'>{props.attendance}</span>
  54. </div>
  55. <div id='trainingRatings'>
  56. <span className='caption'>Rating: </span>
  57. <span className='data'>
  58. {calculateRating(props.ratings)} [
  59. <a href=''>{props.ratings.length}</a>] Rate it!
  60. <a href=''>*</a>
  61. <a href=''>*</a>
  62. <a href=''>*</a>
  63. <a href=''>*</a>
  64. <a href=''>*</a>
  65. </span>
  66. </div>
  67. </aside>
  68. <section>
  69. <h3>Content</h3>
  70. <ol>
  71. {props.content
  72. .sort(block => block.sequence)
  73. .map(block => (
  74. <Block key={block.id} {...block} />
  75. ))}
  76. </ol>
  77. <iframe
  78. width='560'
  79. height='315'
  80. src='https://www.youtube.com/embed/hRz0qPREKho'
  81. frameborder='0'
  82. allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
  83. allowfullscreen
  84. />
  85. </section>
  86. <style jsx>
  87. {`
  88. article {
  89. border: 1px solid black;
  90. }
  91. article > h2 {
  92. font-size: 120%;
  93. font-family: roboto_black;
  94. }
  95. aside {
  96. }
  97. section {
  98. }
  99. `}
  100. </style>
  101. </article>
  102. )
  103. const Block = props => (
  104. <li>
  105. <h2>{props.title}</h2>
  106. <p>
  107. <span className='caption'>Duration: </span>
  108. <span className='data'>{props.duration}</span>
  109. </p>
  110. <p>
  111. <span className='caption'>Variation: </span>
  112. <span className='data'>{props.variation}</span>
  113. </p>
  114. <p>
  115. <span className='caption'>Format: </span>
  116. <span className='data'>
  117. {props.format.name}{' '}
  118. <sup>
  119. <a title={props.format.description}>[?]</a>
  120. </sup>
  121. </span>
  122. </p>
  123. <p>
  124. <span className='caption'>Description: </span>
  125. <span className='data'>{props.description}</span>
  126. </p>
  127. </li>
  128. )
  129. class TrainingCreateForm extends React.Component {
  130. render () {
  131. return (
  132. <form>
  133. <label htmlFor='title'>
  134. Title
  135. <input type='text' id='title' />
  136. </label>
  137. <label htmlFor='title'>
  138. Title
  139. <input type='text' id='title' />
  140. </label>
  141. <label htmlFor='title'>
  142. Title
  143. <input type='text' id='title' />
  144. </label>
  145. </form>
  146. )
  147. }
  148. }
  149. export { TrainingArchive }
  150. export default Training