 window.ReactSigninPopover = React.createClass
   getInitialState: ->
     opened: false
+    callback: null
 
   componentDidMount: ->
     window.currentUser.on 'change:username', @_onSignedInChange, @

  _onOtherPopoverOpened: (popover) ->
    return if popover == this

    @setState opened: false

  _onSignedInChange: ->
    if FactlinkApp.signedIn() && @state.opened
      @_callback()
      @setState opened: false

    @forceUpdate()


    if FactlinkApp.signedIn()
      callback()
    else
      if @state.opened
        @setState opened: false, callback: null
      else
        @setState opened: true, callback: callback
        FactlinkApp.vent.trigger 'ReactSigninPopover:opened', this

  render: ->
