Last active
May 27, 2019 21:57
-
-
Save JeffML/8992c93325e0c947e2bfe2bc0e495174 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Fragment } from 'react'; | |
import { Query } from 'react-apollo'; | |
import gql from 'graphql-tag'; | |
const qLaunches = gql`query ls { | |
launches { | |
launches { | |
id | |
site | |
mission { | |
name | |
} | |
rocket { | |
name | |
type | |
} | |
isBooked | |
} | |
} | |
}`; | |
const launchRows = (data) => { | |
return data.launches && | |
data.launches.launches && | |
data.launches.launches.map((launch) => { | |
const { id, site, mission: { name: missionName }, rocket: { name: rocketName }, isBooked } = launch; | |
return <tr key={id}> | |
<td>{site}</td> | |
<td>{missionName}</td> | |
<td>{rocketName}</td> | |
<td>{isBooked.toString()}</td> | |
</tr> | |
}) | |
} | |
export default function Launches() { | |
return ( | |
<Query query={qLaunches}> | |
{({ data, loading, error }) => { | |
if (loading) return <p>Loading...</p>; | |
if (error) return <p>ERROR</p>; | |
return ( | |
<Fragment> | |
<input type='button' value='make changes' /> | |
<table style={{ border: 'solid 1px' }}> | |
<tbody> | |
<tr> | |
<th>Site</th><th>Mission</th><th>Rocket</th><th>Booked</th> | |
</tr> | |
{launchRows(data)} | |
</tbody> | |
</table> | |
</Fragment> | |
); | |
}} | |
</Query> | |
); | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment