|
@@ -1,11 +1,8 @@
|
|
import theme from '../styles/theme'
|
|
import theme from '../styles/theme'
|
|
-import { Formik, Form } from 'formik'
|
|
|
|
-import { Query } from 'react-apollo'
|
|
|
|
|
|
|
|
-import { TRAINING } from '../lib/graphql'
|
|
|
|
-import { TextInput } from '../lib/forms'
|
|
|
|
|
|
+import TrainingBlock from './trainingBlock'
|
|
|
|
|
|
-function calculateRating(ratings) {
|
|
|
|
|
|
+function calculateRating (ratings) {
|
|
const numberOfRatings = ratings.length
|
|
const numberOfRatings = ratings.length
|
|
const sumOfRatings = ratings.reduce(
|
|
const sumOfRatings = ratings.reduce(
|
|
(accumulator, rating) => accumulator + rating.value,
|
|
(accumulator, rating) => accumulator + rating.value,
|
|
@@ -14,24 +11,6 @@ function calculateRating(ratings) {
|
|
return numberOfRatings ? sumOfRatings / numberOfRatings : '-'
|
|
return numberOfRatings ? sumOfRatings / numberOfRatings : '-'
|
|
}
|
|
}
|
|
|
|
|
|
-const TrainingArchive = props => (
|
|
|
|
- <div>
|
|
|
|
- <h2>Training Archive</h2>
|
|
|
|
- <ol>
|
|
|
|
- {props.trainings.map(training => (
|
|
|
|
- <TrainingHint key={training.id} training={training} />
|
|
|
|
- ))}
|
|
|
|
- </ol>
|
|
|
|
- </div>
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-const TrainingHint = props => (
|
|
|
|
- <div>
|
|
|
|
- <div>{props.training.date}</div>
|
|
|
|
- <div>{props.training.title}</div>
|
|
|
|
- </div>
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
const Training = props => (
|
|
const Training = props => (
|
|
<article>
|
|
<article>
|
|
<h2>{props.title}</h2>
|
|
<h2>{props.title}</h2>
|
|
@@ -78,7 +57,7 @@ const Training = props => (
|
|
{props.content
|
|
{props.content
|
|
.sort(block => block.sequence)
|
|
.sort(block => block.sequence)
|
|
.map(block => (
|
|
.map(block => (
|
|
- <Block key={block.id} {...block} />
|
|
|
|
|
|
+ <TrainingBlock key={block.id} {...block} />
|
|
))}
|
|
))}
|
|
</ol>
|
|
</ol>
|
|
</section>
|
|
</section>
|
|
@@ -133,151 +112,4 @@ const Training = props => (
|
|
</article>
|
|
</article>
|
|
)
|
|
)
|
|
|
|
|
|
-const Youtube = props => {
|
|
|
|
- const { link, rest } = props
|
|
|
|
- const [crap, src] = props.link.match(/\?v=(.*)/)
|
|
|
|
- return (
|
|
|
|
- <iframe
|
|
|
|
- width='285'
|
|
|
|
- height='160'
|
|
|
|
- src={`https://www.youtube.com/embed/${src}`}
|
|
|
|
- frameBorder='0'
|
|
|
|
- allow='accelerometer; autoplay; encrypted-media; gyroscope; picture-in-picture'
|
|
|
|
- allowFullScreen
|
|
|
|
- {...rest}
|
|
|
|
- />
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const Spotify = props => {
|
|
|
|
- const src = props.link.match(/track\/(.*)/)[1]
|
|
|
|
- return (
|
|
|
|
- <iframe
|
|
|
|
- src={`https://open.spotify.com/embed/track/${src}`}
|
|
|
|
- width='300'
|
|
|
|
- height='80'
|
|
|
|
- frameBorder='0'
|
|
|
|
- allowtransparency='true'
|
|
|
|
- allow='encrypted-media'
|
|
|
|
- />
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const Media = props => {
|
|
|
|
- if (props.link.includes('youtube.com')) {
|
|
|
|
- return <Youtube {...props} />
|
|
|
|
- } else if (props.link.includes('spotify.com')) {
|
|
|
|
- return <Spotify {...props} />
|
|
|
|
- } else {
|
|
|
|
- return <p>Link not recognized.</p>
|
|
|
|
- }
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const Block = props => (
|
|
|
|
- <li>
|
|
|
|
- <h2>{props.title}</h2>
|
|
|
|
- <p>
|
|
|
|
- <span className='caption'>Duration: </span>
|
|
|
|
- <span className='data'>{props.duration}</span>
|
|
|
|
- </p>
|
|
|
|
- <p>
|
|
|
|
- <span className='caption'>Variation: </span>
|
|
|
|
- <span className='data'>{props.variation}</span>
|
|
|
|
- </p>
|
|
|
|
- <p>
|
|
|
|
- <span className='caption'>Description: </span>
|
|
|
|
- <span className='data'>{props.description}</span>
|
|
|
|
- </p>
|
|
|
|
- <p>
|
|
|
|
- <span className='caption'>Format: </span>
|
|
|
|
- <span className='data'>
|
|
|
|
- {props.format.name}{' '}
|
|
|
|
- <sup>
|
|
|
|
- <a title={props.format.description}>[?]</a>
|
|
|
|
- </sup>
|
|
|
|
- </span>
|
|
|
|
- </p>
|
|
|
|
- <section>
|
|
|
|
- <h2>Tracks</h2>
|
|
|
|
- <ol>
|
|
|
|
- {props.tracks.map(track => (
|
|
|
|
- <Track key={track.id} {...track} />
|
|
|
|
- ))}
|
|
|
|
- </ol>
|
|
|
|
- </section>
|
|
|
|
- <section>
|
|
|
|
- <h2>Exercises</h2>
|
|
|
|
- <ol>
|
|
|
|
- {props.exercises.map(exercise => (
|
|
|
|
- <Exercise key={exercise.id} {...exercise} />
|
|
|
|
- ))}
|
|
|
|
- </ol>
|
|
|
|
- </section>
|
|
|
|
-
|
|
|
|
- <style jsx>
|
|
|
|
- {`
|
|
|
|
- section {
|
|
|
|
- display: grid;
|
|
|
|
- }
|
|
|
|
- `}
|
|
|
|
- </style>
|
|
|
|
- </li>
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-const Track = props => {
|
|
|
|
- return (
|
|
|
|
- <section>
|
|
|
|
- <p>
|
|
|
|
- Track {props.id}: {props.title} ({props.artist})
|
|
|
|
- </p>
|
|
|
|
- <Media link={props.link} />
|
|
|
|
- </section>
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const Exercise = props => {
|
|
|
|
- return (
|
|
|
|
- <section>
|
|
|
|
- <p>
|
|
|
|
- Exercise {props.id}: {props.name}
|
|
|
|
- </p>
|
|
|
|
- </section>
|
|
|
|
- )
|
|
|
|
-}
|
|
|
|
-
|
|
|
|
-const TrainingCreateForm = props => (
|
|
|
|
- <Formik
|
|
|
|
- initialVariables={{
|
|
|
|
- title: '',
|
|
|
|
- type: '',
|
|
|
|
- content: [],
|
|
|
|
- trainingDate: '',
|
|
|
|
- location: '',
|
|
|
|
- registration: [],
|
|
|
|
- attendance: 0,
|
|
|
|
- ratings: [],
|
|
|
|
- published: false
|
|
|
|
- }}
|
|
|
|
- onSubmit={ev => console.log(ev)}
|
|
|
|
- >
|
|
|
|
- {() => (
|
|
|
|
- <Form>
|
|
|
|
- <label htmlFor='title'>
|
|
|
|
- Title
|
|
|
|
- <input type='text' id='title' />
|
|
|
|
- </label>
|
|
|
|
- <label htmlFor='title'>
|
|
|
|
- Title
|
|
|
|
- <input type='text' id='title' />
|
|
|
|
- </label>
|
|
|
|
- <label htmlFor='title'>
|
|
|
|
- Title
|
|
|
|
- <input type='text' id='title' />
|
|
|
|
- </label>
|
|
|
|
- </Form>
|
|
|
|
- )}
|
|
|
|
- </Formik>
|
|
|
|
-)
|
|
|
|
-
|
|
|
|
-export { TrainingArchive, TrainingCreateForm }
|
|
|
|
export default Training
|
|
export default Training
|