instruments.js 732 B

1234567891011121314151617181920212223
  1. import { Query } from 'react-apollo'
  2. import Instrument, { INSTRUMENT_QUERY } from '../components/Instrument'
  3. import InstrumentList from '../components/InstrumentList'
  4. const InstrumentsPage = props =>
  5. props.query && props.query.id ? (
  6. <Query query={INSTRUMENT_QUERY} variables={{ id: props.query.id }}>
  7. {({ data, loading, error }) => {
  8. if (loading) return <p>Loading instrument...</p>
  9. if (error) return <p>Error loading instrument: {error.message}</p>
  10. const { instrument } = data
  11. return <Instrument instrument={instrument} />
  12. }}
  13. </Query>
  14. ) : (
  15. <InstrumentList />
  16. )
  17. InstrumentsPage.getInitialProps = ({ query }) => {
  18. return { query }
  19. }
  20. export default InstrumentsPage