Skip to content

Instantly share code, notes, and snippets.

@claym
Created July 8, 2017 00:25
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save claym/30ce55eed93ba01687950e873215d079 to your computer and use it in GitHub Desktop.
Save claym/30ce55eed93ba01687950e873215d079 to your computer and use it in GitHub Desktop.
import React from 'react';
import ReactDOM from 'react-dom';
import { graphql } from 'react-apollo';
import PropTypes from 'prop-types';
import Drawer from 'material-ui/Drawer';
import MenuItem from 'material-ui/MenuItem';
import allLocations from '../queries/all_locations.gql';
@graphql(allLocations)
class Sidebar extends React.Component {
static propTypes = {
data: PropTypes.shape({
loading: PropTypes.bool.isRequired,
error: PropTypes.object.isRequired,
allLocations: PropTypes.arrayOf(
PropTypes.shape({
name: PropTypes.string.isRequired,
id: PropTypes.number.isRequired,
}),
),
}),
}
render() {
if (this.props.data.loading) {
return (<div>Loading</div>)
}
if (this.props.data.error) {
console.log(this.props.data.error)
return (<div>An unexpected error occurred</div>)
}
return (
<Drawer docked={true} style={{ width: 125 }}>
{this.props.data.allLocations.map(location =>
<MenuItem key={location.id}>{location.name}</MenuItem>
)}
</Drawer>
)
}
}
export default Sidebar;
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment