Mailspring/internal_packages/search-bar/lib/search-suggestion-store.coffee
Evan Morikawa 0e0f296866 fix(*): fix draft preparing
Summary:
Fixes T1162: Search no longer lowercases

Fixes T1212: Selection anchor nodes are restored properly

Fixes T1254: Make sessionForLocalId return a promise

Test Plan: edgehill --test

Reviewers: bengotow

Reviewed By: bengotow

Subscribers: mg

Maniphest Tasks: T1263, T1212, T1162, T1254

Differential Revision: https://review.inboxapp.com/D1512
2015-05-15 10:45:18 -07:00

72 lines
1.7 KiB
CoffeeScript

Reflux = require 'reflux'
{Actions,
Contact,
ContactStore} = require 'inbox-exports'
_ = require 'underscore-plus'
# Stores should closely match the needs of a particular part of the front end.
# For example, we might create a "MessageStore" that observes this store
# for changes in selectedThread, "DatabaseStore" for changes to the underlying database,
# and vends up the array used for that view.
SearchSuggestionStore = Reflux.createStore
init: ->
@_suggestions = []
@_query = ""
@_committedQuery = ""
@listenTo Actions.searchQueryChanged, @onSearchQueryChanged
@listenTo Actions.searchQueryCommitted, @onSearchQueryCommitted
@listenTo Actions.searchBlurred, @onSearchBlurred
onSearchQueryChanged: (query) ->
@_query = query
@repopulate()
onSearchQueryCommitted: (query) ->
@_query = query
@_committedQuery = query
@_suggestions = []
@trigger()
onSearchBlurred: ->
@_suggestions = []
@trigger()
repopulate: ->
@_suggestions = []
term = @_query?[0]
return @trigger(@) unless term
key = Object.keys(term)[0]
val = term[key]
return @trigger(@) unless val
contactResults = ContactStore.searchContacts(val, limit:10)
@_suggestions.push
label: "Message Contains: #{val}"
value: [{"all": val}]
if contactResults.length
@_suggestions.push
divider: 'People'
_.each contactResults, (contact) =>
@_suggestions.push
contact: contact
value: [{"participants": contact.email}]
@trigger(@)
# Exposed Data
query: -> @_query
committedQuery: -> @_committedQuery
suggestions: ->
@_suggestions
module.exports = SearchSuggestionStore