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

View file

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

View file

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

View file

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

View file

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

View file

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