index.js 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Query } from 'react-apollo'
  2. import Link from 'next/link'
  3. import Training from '../components/training'
  4. import initialData from '../initial-data.js'
  5. import { TRAININGS } from '../lib/graphql'
  6. console.log(initialData)
  7. const Home = () => (
  8. <>
  9. <section>
  10. <h1>Stay in Shape with u-fit</h1>
  11. <p>u-fit is a high intensity interval training offered by u-blox.</p>
  12. <aside>
  13. <div id='trainingTime'>
  14. <span className='caption'>When</span>
  15. <span className='data'>Tuesdays, 11:45-12:30</span>
  16. </div>
  17. <div id='trainingEquipment'>
  18. <span className='caption'>Equipment</span>
  19. <span className='data'>Towel, water, optional: yoga mat</span>
  20. </div>
  21. </aside>
  22. </section>
  23. <section id='nextTraining'>
  24. <Query query={TRAININGS}>{
  25. ({ data, error, loading }) => {
  26. if (error) return (<p>Error {error.message}</p>)
  27. if (loading) return (<p>Loading...</p>)
  28. if (data.trainings.length) {
  29. console.log(data)
  30. return (
  31. <>
  32. <Training
  33. {...{
  34. ...data.trainings[data.trainings.length - 1],
  35. title: `Your Next Training: ${
  36. data.trainings[data.trainings.length - 1].title
  37. }`
  38. }}
  39. />
  40. </>
  41. )
  42. } else return <p>Nothing found...</p>
  43. }
  44. }
  45. </Query>
  46. <Link href={{ pathname: '/training' }}><a>create training...</a></Link>
  47. </section>
  48. </>
  49. )
  50. export default Home