fix(search): Fix for broken search display

This commit is contained in:
Ben Gotow 2015-09-04 15:31:03 -07:00
parent 3f18a3659f
commit 692291364a
6 changed files with 41 additions and 32 deletions

View file

@ -21,8 +21,6 @@ class ThreadListStore extends NylasStore
constructor: ->
@_resetInstanceVars()
@listenTo Actions.searchQueryCommitted, @_onSearchCommitted
@listenTo Actions.archiveAndPrevious, @_onArchiveAndPrev
@listenTo Actions.archiveAndNext, @_onArchiveAndNext
@ -50,7 +48,6 @@ class ThreadListStore extends NylasStore
_resetInstanceVars: ->
@_lastQuery = null
@_searchQuery = null
view: ->
@_view
@ -69,12 +66,11 @@ class ThreadListStore extends NylasStore
createView: ->
mailViewFilter = FocusedMailViewStore.mailView()
account = AccountStore.current()
return unless account
return unless account and mailViewFilter
if @_searchQuery
@setView(new SearchView(@_searchQuery, account.id))
else if account.id and mailViewFilter
if mailViewFilter.searchQuery
@setView(new SearchView(mailViewFilter.searchQuery, account.id))
else
matchers = []
matchers.push Thread.attributes.accountId.equal(account.id)
matchers = matchers.concat(mailViewFilter.matchers())
@ -107,11 +103,6 @@ class ThreadListStore extends NylasStore
return if @_view and _.find(@_view.matchers, accountMatcher)
@createView()
_onSearchCommitted: (query) ->
return if @_searchQuery is query
@_searchQuery = query
@createView()
_onDataChanged: (change) ->
return unless @_view

View file

@ -32,16 +32,16 @@ describe "FocusedMailViewStore", ->
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@inboxCategory.id)
describe "_onSearchQueryCommitted", ->
it "should clear the focused category and trigger when a search query is committed", ->
it "should change to a search mail view when a search query is committed", ->
FocusedMailViewStore._onFocusMailView(@userFilter)
FocusedMailViewStore._onSearchQueryCommitted('bla')
expect(FocusedMailViewStore.trigger).toHaveBeenCalled()
expect(FocusedMailViewStore.mailView()).toBe(null)
expect(FocusedMailViewStore.mailView().isEqual(MailViewFilter.forSearch('bla'))).toBe(true)
it "should restore the category that was previously focused and trigger when a search query is cleared", ->
FocusedMailViewStore._onFocusMailView(@userFilter)
FocusedMailViewStore._onSearchQueryCommitted('bla')
expect(FocusedMailViewStore.mailView()).toEqual(null)
expect(FocusedMailViewStore.mailView().isEqual(MailViewFilter.forSearch('bla'))).toBe(true)
FocusedMailViewStore._onSearchQueryCommitted('')
expect(FocusedMailViewStore.trigger).toHaveBeenCalled()
expect(FocusedMailViewStore.mailView().categoryId()).toEqual(@userCategory.id)

View file

@ -15,9 +15,8 @@ class FocusedMailViewStore extends NylasStore
_onCategoryStoreChanged: ->
if not @_mailView
@_setMailView(@_defaultMailView())
else
if not CategoryStore.byId(@_mailView.categoryId())
@_setMailView(@_defaultMailView())
else if not CategoryStore.byId(@_mailView.categoryId())
@_setMailView(@_defaultMailView())
_onFocusMailView: (filter) ->
return if filter.isEqual(@_mailView)
@ -28,14 +27,14 @@ class FocusedMailViewStore extends NylasStore
_onSearchQueryCommitted: (query="") ->
if typeof(query) != "string"
query = query[0].all
if query.trim().length > 0 and @_mailView
@_mailViewBeforeSearch = @_mailView
@_setMailView(null)
if query.trim().length > 0
@_mailViewBeforeSearch ?= @_mailView
@_setMailView(MailViewFilter.forSearch(query))
else if query.trim().length is 0
if @_mailViewBeforeSearch
@_setMailView(@_mailViewBeforeSearch)
else
@_setMailView(@_defaultMailView())
@_mailViewBeforeSearch ?= @_defaultMailView()
@_setMailView(@_mailViewBeforeSearch)
@_mailViewBeforeSearch = null
_defaultMailView: ->
category = CategoryStore.getStandardCategory('inbox')

View file

@ -56,7 +56,7 @@ class SearchView extends ModelView
NylasAPI.makeRequest
method: 'GET'
path: "/threads/search?q=#{@_query[0].all}"
path: "/threads/search?q=#{@_query}"
accountId: @_accountId
json: true
returnsModel: false

View file

@ -18,6 +18,9 @@ class MailViewFilter
@forStarred: ->
new StarredMailViewFilter()
@forSearch: (query) ->
new SearchMailViewFilter(query)
# Instance Methods
constructor: ->
@ -26,8 +29,8 @@ class MailViewFilter
return false unless other and @constructor.name is other.constructor.name
return false if other.name isnt @name
matchers = @matchers()
otherMatchers = other.matchers()
matchers = @matchers() ? []
otherMatchers = other.matchers() ? []
return false if otherMatchers.length isnt matchers.length
for idx in [0...matchers.length]
@ -49,6 +52,23 @@ class MailViewFilter
throw new Error("applyToThreads: Not implemented in base class.")
class SearchMailViewFilter extends MailViewFilter
constructor: (@searchQuery) ->
@
isEqual: (other) ->
super(other) and other.searchQuery is @searchQuery
matchers: ->
null
canApplyToThreads: ->
false
categoryId: ->
null
class StarredMailViewFilter extends MailViewFilter
constructor: ->
@name = "Starred"

View file

@ -33,9 +33,8 @@ class Sheet extends React.Component
componentDidUpdate: =>
@props.onColumnSizeChanged(@) if @props.onColumnSizeChanged
minWidth = @state.columns
.map((c) -> c.minWidth)
.reduce((total, next) -> total + next)
minWidth = 0
minWidth += col.minWidth for col in @state.columns
atom.setMinimumWidth(minWidth)
shouldComponentUpdate: (nextProps, nextState) =>