InstrumentList.js 1.3 KB

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