     user: null
 
   getInitialState: ->
-    favoritesPromise: null
-    favoritedPromise: null
-    favorites: {}
+    favorites: null
     favorited: false
 
   contextTypes:
-    geordi: React.PropTypes.object
+    geordi: React.PropTypes.object 
 
   logSubjLike: (liked) ->
     @context.geordi?.logEvent

    links.projects = [ project ] if project?
    collection = {favorite, display_name, links}

    apiClient.type('collections').create(collection).save().then =>
      @setState favoritedPromise: Promise.resolve(true)

  toggleFavorite: ->
    if @props.user?
      Promise.all([@state.favoritesPromise, @state.favoritedPromise])
        .then ([favorites, favorited]) =>
          if not favorites?
            @createFavorites()
            @logSubjLike 'favorite'
          else if favorited
            @removeSubjectFrom(favorites)
            @logSubjLike 'unfavorite'
          else
            @addSubjectTo(favorites)
            @logSubjLike 'favorite'
    else
      @promptToSignIn()
      @logSubjLike 'favorite'

  render: ->
    <PromiseRenderer promise={@state.favoritedPromise}>{(favorited) =>
      <button
        className="favorites-button #{@props.className ? ''}"
        type="button"
        title={if favorited then 'Unfavorite' else 'Favorite'}
        onClick={@toggleFavorite}>
        <i className="
          fa fa-heart#{if favorited then '' else '-o'}
          #{if favorited then 'favorited' else ''}
          fa-fw
        " />
      </button>
    }</PromiseRenderer>

getFavoritesName = require './get-favorites-name'
alert = require '../lib/alert'
SignInPrompt = require '../partials/sign-in-prompt'

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