training.js 4.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184
  1. function calculateRating(ratings) {
  2. const numberOfRatings = ratings.length
  3. const sumOfRatings = ratings.reduce(
  4. (accumulator, rating) => accumulator + rating.value,
  5. 0
  6. )
  7. return numberOfRatings ? sumOfRatings / numberOfRatings : '-'
  8. }
  9. const TrainingArchive = props => (
  10. <div>
  11. <h2>Training Archive</h2>
  12. <ol>
  13. {props.trainings.map(training => (
  14. <TrainingHint key={training.id} training={training} />
  15. ))}
  16. </ol>
  17. </div>
  18. )
  19. const TrainingHint = props => (
  20. <div>
  21. <div>{props.training.date}</div>
  22. <div>{props.training.title}</div>
  23. </div>
  24. )
  25. const Training = props => (
  26. <article>
  27. <h2>{props.title}</h2>
  28. <aside>
  29. <div id='trainingType'>
  30. <span className='caption'>Type: </span>
  31. <span className='data'>{props.type.name}</span>
  32. </div>
  33. <div id='trainingDate'>
  34. <span className='caption'>Date: </span>
  35. <span className='data'>
  36. {new Date(props.trainingDate).toLocaleDateString()}
  37. </span>
  38. </div>
  39. <div id='trainingLocation'>
  40. <span className='caption'>Location: </span>
  41. <span className='data'>{props.location}</span>
  42. </div>
  43. <div id='trainingRegistrations'>
  44. <span className='caption'>Registrations: </span>
  45. <span className='data'>
  46. {props.registration.length} <a href=''>Register!</a>
  47. </span>
  48. </div>
  49. <div id='trainingAttendance'>
  50. <span className='caption'>Attendance: </span>
  51. <span className='data'>{props.attendance}</span>
  52. </div>
  53. <div id='trainingRatings'>
  54. <span className='caption'>Rating: </span>
  55. <span className='data'>
  56. {calculateRating(props.ratings)} [
  57. <a href=''>{props.ratings.length}</a>] Rate it!
  58. <a href=''>*</a>
  59. <a href=''>*</a>
  60. <a href=''>*</a>
  61. <a href=''>*</a>
  62. <a href=''>*</a>
  63. </span>
  64. </div>
  65. </aside>
  66. <section>
  67. <h3>Content</h3>
  68. <ol>
  69. {props.content
  70. .sort(block => block.sequence)
  71. .map(block => (
  72. <Block key={block.id} {...block} />
  73. ))}
  74. </ol>
  75. </section>
  76. <style jsx>
  77. {`
  78. article > h2 {
  79. font-weight: 900;
  80. font-size: 120%;
  81. }
  82. aside {
  83. }
  84. section {
  85. }
  86. `}
  87. </style>
  88. </article>
  89. )
  90. const Youtube = props => {
  91. const { link, rest } = props
  92. const [crap, src] = props.link.match(/\?v=(.*)/)
  93. return <iframe
  94. width='285'
  95. height='160'
  96. src={`https://www.youtube.com/embed/${src}`}
  97. frameBorder='0'
  98. allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
  99. allowFullScreen
  100. {...rest}
  101. />
  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'>Description: </span>
  116. <span className='data'>{props.description}</span>
  117. </p>
  118. <p>
  119. <span className='caption'>Format: </span>
  120. <span className='data'>
  121. {props.format.name}{' '}
  122. <sup>
  123. <a title={props.format.description}>[?]</a>
  124. </sup>
  125. </span>
  126. </p>
  127. <section>
  128. <h2>Tracks</h2>
  129. <ol>
  130. {props.tracks.map(track => <Track key={track.id} {...track} />)}
  131. </ol>
  132. </section>
  133. <section>
  134. <h2>Exercises</h2>
  135. <ol>
  136. {props.exercises.map(exercise => <Exercise key={exercise.id} {...exercise} />)}
  137. </ol>
  138. </section>
  139. </li>
  140. )
  141. const Track = props => {
  142. return <section>
  143. <p>Track {props.id}: {props.title} ({props.artist})</p>
  144. <Youtube link={props.link} />
  145. </section>
  146. }
  147. const Exercise = props => {
  148. return <section>
  149. <p>Exercise {props.id}: {props.name}</p>
  150. </section>
  151. }
  152. class TrainingCreateForm extends React.Component {
  153. render() {
  154. return (
  155. <form>
  156. <label htmlFor='title'>
  157. Title
  158. <input type='text' id='title' />
  159. </label>
  160. <label htmlFor='title'>
  161. Title
  162. <input type='text' id='title' />
  163. </label>
  164. <label htmlFor='title'>
  165. Title
  166. <input type='text' id='title' />
  167. </label>
  168. </form>
  169. )
  170. }
  171. }
  172. export { TrainingArchive }
  173. export default Training