mirror of
https://github.com/Foundry376/Mailspring.git
synced 2024-09-22 00:06:06 +08:00
fix(search): Fix for broken search display
This commit is contained in:
parent
3f18a3659f
commit
692291364a
|
@ -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
|
||||
|
||||
|
|
|
@ -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)
|
||||
|
|
|
@ -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')
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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"
|
||||
|
|
|
@ -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) =>
|
||||
|
|
Loading…
Reference in a new issue