InstrumentList.js 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. import gql from 'graphql-tag'
  2. import { Query } from 'react-apollo'
  3. import Link from 'next/link'
  4. const INSTRUMENTS = gql`
  5. query INSTRUMENTS {
  6. instruments {
  7. id
  8. name
  9. description
  10. }
  11. }
  12. `
  13. const InstrumentList = props => (
  14. <Query query={INSTRUMENTS}>
  15. {({ data, loading, error }) => {
  16. const content = [
  17. <h1>Instrument List</h1>
  18. ]
  19. if (loading) content.push(<p>Loading instruments...</p>)
  20. if (error) content.push(<p>Error loading instruments: {error.message}</p>)
  21. if (data.instruments.length > 0) {
  22. content.push(
  23. <ul>
  24. {data.instruments.map(instrument => (
  25. <li key={instrument.id} title={instrument.description}>
  26. <Link href={{ pathname: 'instruments', query: { id: instrument.id } }}>
  27. <a>{instrument.name}</a>
  28. </Link>
  29. </li>
  30. ))}
  31. </ul>
  32. )
  33. } else {
  34. content.push(<p>No instruments found.</p>)
  35. }
  36. return content
  37. }}
  38. </Query>
  39. )
  40. export default InstrumentList