<commit_before>React = require 'react'
PromiseRenderer = require '../../components/promise-renderer'
talkClient = require 'panoptes-client/lib/talk-client'
userIsZooniverseAdmin = require './user-is-zooniverse-admin'

module.exports = React.createClass
  displayName: 'ZooniverseTeam'

  propTypes:
    section: React.PropTypes.string.isRequired # talk section
    user: React.PropTypes.object.isRequired

  getInitialState: ->
    open: false

  render: ->
    {section} = @props

    <div>
      <PromiseRenderer pending={null} promise={talkClient.type('roles').get(user_id: @props.user.id, section: ['zooniverse', section], page_size: 100)}>{(roles) =>

        if userIsZooniverseAdmin(roles)
          @props.children
        else
          null

      }</PromiseRenderer>
    </div><commit_msg>remove PromiseRenderer from Zoo team component<commit_after>React = require 'react'
talkClient = require 'panoptes-client/lib/talk-client'
userIsZooniverseAdmin = require './user-is-zooniverse-admin'

module.exports = React.createClass
  displayName: 'ZooniverseTeam'

  propTypes:
    section: React.PropTypes.string.isRequired # talk section
    user: React.PropTypes.object.isRequired

  getInitialState: ->
    open: false
    roles: []

  componentDidMount: ->
    @updateRoles @props.user

  componentWillReceiveProps: (newProps) ->
    @updateRoles newProps.user if newProps.user isnt @props.user

  updateRoles: (user) ->
    talkClient.type 'roles'
      .get
        user_id: user.id
        section: ['zooniverse', @props.section]
        page_size: 100
      .then (roles) =>
        @setState {roles}

  render: ->
    {section} = @props

    <div>
      {if userIsZooniverseAdmin(@state.roles)
        @props.children
      else
        null
      }
    </div>
{'fraction_non_alphanumeric': 0.12063134160090191, 'fraction_numerical': 0.0033821871476888386, 'mean_word_length': 3.127906976744186, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 18, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '4480817', 'n_tokens_mistral': 566, 'n_tokens_neox': 549, 'n_words': 111}