123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127 |
- import theme from '../../styles/theme'
- import PropTypes from 'prop-types'
- import TrainingType from './trainingType'
- import TrainingBlock from './trainingBlock'
- function calculateRating (ratings) {
- const numberOfRatings = ratings.length
- const sumOfRatings = ratings.reduce(
- (accumulator, rating) => accumulator + rating.value,
- 0
- )
- return numberOfRatings ? sumOfRatings / numberOfRatings : '-'
- }
- const Training = props => (
- <article>
- <h2>{props.title}</h2>
- <aside>
- <div id='trainingType'>
- <span className='caption'>Type: </span>
- <span className='data'>{props.type.name}</span>
- </div>
- <div id='trainingDate'>
- <span className='caption'>Date: </span>
- <span className='data'>
- {new Date(props.trainingDate).toLocaleDateString()}
- </span>
- </div>
- <div id='trainingLocation'>
- <span className='caption'>Location: </span>
- <span className='data'>{props.location}</span>
- </div>
- <div id='trainingRegistrations'>
- <span className='caption'>Registrations: </span>
- <span className='data'> {props.registration.length} </span>
- </div>
- <div id='trainingAttendance'>
- <span className='caption'>Attendance: </span>
- <span className='data'>{props.attendance}</span>
- </div>
- <div id='trainingRatings'>
- <span className='caption'>Rating: </span>
- <span className='data'>
- {calculateRating(props.ratings)} [
- <a href=''>{props.ratings.length}</a>] Rate it!
- <a href=''>*</a>
- <a href=''>*</a>
- <a href=''>*</a>
- <a href=''>*</a>
- <a href=''>*</a>
- </span>
- </div>
- <button>Register now!</button>
- </aside>
- <section>
- <h3>Content</h3>
- <ol>
- {props.content
- .sort(block => block.sequence)
- .map(block => (
- <TrainingBlock key={block.id} {...block} />
- ))}
- </ol>
- </section>
- <style jsx>
- {`
- article {
- display: grid;
- grid-template-areas:
- 'title title'
- 'information placeholder'
- 'content content';
- grid-template-columns: 1fr 2fr;
- background-color: rgba(127, 127, 127, 0.5);
- background-image: url('media/man_working_out.jpg');
- background-size: auto 400px;
- background-repeat: no-repeat;
- margin: 2em 0;
- }
- article > * {
- padding: 0.2em 1em;
- }
- article > h2 {
- grid-area: title;
- font-weight: 900;
- font-size: 120%;
- background: ${theme.colors.darkerblue};
- color: ${theme.colors.offWhite};
- }
- aside {
- grid-area: information;
- background: rgba(0, 127, 0, 0.5);
- padding: 1em 2em;
- margin: 0 1em;
- min-height: 350px;
- }
- section {
- grid-area: content;
- padding: 1em 2em;
- background: rgba(127, 0, 0, 0.5);
- }
- span.caption {
- display: none;
- }
- `}
- </style>
- </article>
- )
- Training.propTypes = {
- title: PropTypes.string.isRequired,
- type: PropTypes.shape(TrainingType.propTypes).isRequired,
- content: PropTypes.arrayOf(TrainingBlock.propTypes).isRequired,
- createdAt: PropTypes.number,
- trainingDate: PropTypes.number.isRequired,
- location: PropTypes.string.isRequired,
- registration: PropTypes
- }
- export default Training
|