import React, { Component } from 'react' import {graphql, compose} from 'react-apollo' import {getUserProfileQuery} from '../queries/queries' // Materia UI import { withStyles } from '@material-ui/core/styles' import Grid from '@material-ui/core/Grid' import Card from '@material-ui/core/Card' import CardActionArea from '@material-ui/core/CardActionArea' import CardContent from '@material-ui/core/CardContent' import CardMedia from '@material-ui/core/CardMedia' import Typography from '@material-ui/core/Typography' import Divider from '@material-ui/core/Divider' // Images import UserDefaultPicture from '../img/user-default-pic.jpg' const styles = theme => ({ root: { flexGrow: 1, padding: 60, margin: 2 }, card: { maxWidth: 500, minWidth: 500, paddingTop: '30' }, media: { height: 0, paddingTop: '56.25%', // 16:9, marginTop: '30', minWidth: '80%' }, grid: { paddingTop: '30', marginTop: '30' }, typography: { width: '100%', marginTop: 20, marginBottom: 20 } }) class UserProfile extends Component { displayNames () { const user = this.props.data.users_User const { classes } = this.props if (user.firstName !== null && user.lastName !== null) { return ( { user.firstName + ' ' + user.lastName} ) } } displayRole () { const user = this.props.data.users_User const { classes } = this.props if (user.role.name !== null && user.role.name !== 'Not Defined') { return (
{ user.role.name }
) } } displayBio () { const user = this.props.data.users_User const { classes } = this.props if (user.bio !== null && user.bio !== '') { return (
{ user.bio }
) } } displayUserProfile () { const user = this.props.data.users_User const { classes } = this.props if (user) { return ( { this.setState({ selected: user.id}) } }> {this.displayNames()} {user.alias} {this.displayRole()} {this.displayBio()} ) } else { return (
No User selected...
) } } render () { return ( {this.displayUserProfile()} ) } } export default compose( graphql(getUserProfileQuery, { // What follows is the way to pass a parameter to a query. options: (props) => { return { variables: { name: 'getUserProfileQuery', id: props.userId } } }}), withStyles(styles) )(UserProfile) // This technique binds more than one query to a single component.