index.js 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  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. </Query>
  45. <Link href={{ pathname: '/training' }}>
  46. <a>create training...</a>
  47. </Link>
  48. </section>
  49. </>
  50. )
  51. export default Home