<commit_before>React = require 'react'
apiClient = require '../../api/client'
{Navigation} = require 'react-router'
Loading = require '../../components/loading-indicator'

module?.exports = React.createClass
  displayName: 'ProjectLinker'
  mixins: [Navigation]

  getInitialState: ->
    projects: []
    loading: true

  componentWillMount: ->
    @setProjects()

  shouldComponentUpdate: (nextProps, nextState) ->
    nextState.projects isnt @state.projects

  goToProjectTalk: (projectId) ->
    apiClient.type('projects').get(projectId.toString()).then (project) =>
      project.get('owner').then (owner) =>
        @transitionTo 'project-talk', 
          owner: owner.login
          name: project.slug

  setProjects: (metadata) ->
    apiClient.type('projects').get()
      .then (projects) =>
        @setState {projects, loading: false}

  onChangeSelect: (e) ->
    projectsSelect = React.findDOMNode(@).querySelector('select')
    projectId = projectsSelect.options[projectsSelect.selectedIndex].value
    @goToProjectTalk(projectId)

  projectOption: (d, i) ->
    <option key={d.id} value={d.id}>
      {d.display_name}
    </option>
    
  render: -><commit_msg>Only show approved projects in Talk sidebar<commit_after>React = require 'react'
apiClient = require '../../api/client'
{Navigation} = require 'react-router'
Loading = require '../../components/loading-indicator'

module?.exports = React.createClass
  displayName: 'ProjectLinker'
  mixins: [Navigation]

  getInitialState: ->
    projects: []
    loading: true

  componentWillMount: ->
    @setProjects()

  shouldComponentUpdate: (nextProps, nextState) ->
    nextState.projects isnt @state.projects

  goToProjectTalk: (projectId) ->
    apiClient.type('projects').get(projectId.toString()).then (project) =>
      project.get('owner').then (owner) =>
        @transitionTo 'project-talk', 
          owner: owner.login
          name: project.slug

  setProjects: (metadata) ->
    query =
      launch_approved: true
      include: 'owners'

    apiClient.type('projects').get(query)
      .then (projects) =>
        @setState {projects, loading: false}

  onChangeSelect: (e) ->
    projectsSelect = React.findDOMNode(@).querySelector('select')
    projectId = projectsSelect.options[projectsSelect.selectedIndex].value
    @goToProjectTalk(projectId)

  projectOption: (d, i) ->
    <option key={d.id} value={d.id}>
      {d.display_name}
    </option>
    
  render: ->
{'fraction_non_alphanumeric': 0.14605370219690805, 'fraction_numerical': 0.0, 'mean_word_length': 3.3754448398576513, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 29, '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': '905426', 'n_tokens_mistral': 736, 'n_tokens_neox': 726, 'n_words': 145}