{"size": 1496, "ext": "js", "max_stars_repo_path": "js/components/RoleSwitch.js", "max_stars_repo_name": "rblakeley/relay-players-positions", "max_stars_repo_stars_event_min_datetime": "2015-11-26T08:14:37.000Z", "max_stars_repo_stars_event_max_datetime": "2016-04-21T13:11:43.000Z", "max_issues_repo_path": "js/components/RoleSwitch.js", "max_issues_repo_name": "rblakeley/relay-players-positions", "max_issues_repo_issues_event_min_datetime": null, "max_issues_repo_issues_event_max_datetime": null, "max_forks_repo_path": "js/components/RoleSwitch.js", "max_forks_repo_name": "rblakeley/relay-players-positions", "max_forks_repo_forks_event_min_datetime": null, "max_forks_repo_forks_event_max_datetime": null}
{"max_stars_count": 3, "max_issues_count": null, "max_forks_count": null, "avg_line_length": 23.375, "max_line_length": 73, "alphanum_fraction": 0.5895721925}
import RemoveUserRoleMutation from '../mutations/RemoveUserRoleMutation';
import AddUserRoleMutation from '../mutations/AddUserRoleMutation';
import React from 'react';
import Relay from 'react-relay';

class RoleSwitch extends React.Component {
  getStyles () {
    var {connected} = this.props;
    return {
      container: {
        display: 'inline-block',
        fontWeight: connected ? 'bold' : 'normal',
      },
    };
  }
  _handleClick = () => {
    this.props.connected ? this._removeRole() : this._addRole();
  }
  _removeRole () {
    Relay.Store.update(
      new RemoveUserRoleMutation({
        user: this.props.user,
        role: this.props.role,
      })
    );
  }
  _addRole () {
    Relay.Store.update(
      new AddUserRoleMutation({
        user: this.props.user,
        role: this.props.role,
      })
    );
  }
  render () {
    var {role} = this.props;
    var styles = this.getStyles();
    return <div style={styles.container} onClick={this._handleClick}>
      {role.name.charAt(0)}
    </div>;
  }
}

export default Relay.createContainer(RoleSwitch, {
  fragments: {
    role: () => Relay.QL`
      fragment on Role {
        id,
        name,
        ${RemoveUserRoleMutation.getFragment('role')},
        ${AddUserRoleMutation.getFragment('role')},
      }
    `,
    user: () => Relay.QL`
      fragment on User {
        id,
        ${RemoveUserRoleMutation.getFragment('user')},
        ${AddUserRoleMutation.getFragment('user')},
      }
    `,
  },
});

