React = require 'react/addons'
classNames = require 'classnames'
{Actions, WorkspaceStore} = require 'nylas-exports'
{Menu, RetinaImg, KeyCommandsRegion} = require 'nylas-component-kit'
SearchSuggestionStore = require './search-suggestion-store'
_ = require 'underscore'
class SearchBar extends React.Component
@displayName = 'SearchBar'
constructor: (@props) ->
@state =
query: ""
focused: false
suggestions: []
committedQuery: null
componentDidMount: =>
@usub = []
@usub.push SearchSuggestionStore.listen @_onChange
@usub.push WorkspaceStore.listen =>
@setState(focused: false) if @state.focused
# It's important that every React class explicitly stops listening to
# N1 events before it unmounts. Thank you event-kit
# This can be fixed via a Reflux mixin
componentWillUnmount: =>
usub() for usub in @usub
_keymapHandlers: ->
'application:focus-search': @_onFocusSearch
'search-bar:escape-search': @_clearAndBlur
render: =>
inputValue = @_queryToString(@state.query)
inputClass = classNames
'input-bordered': true
'empty': inputValue.length is 0
headerComponents = [