Made article search go fast
This commit is contained in:
parent
8002839941
commit
67b9721a10
|
@ -49,6 +49,7 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||||
private var expandedNodes = [Node]()
|
private var expandedNodes = [Node]()
|
||||||
private var shadowTable = [[Node]]()
|
private var shadowTable = [[Node]]()
|
||||||
private var lastSearchString = ""
|
private var lastSearchString = ""
|
||||||
|
private var isSearching: Bool = false
|
||||||
|
|
||||||
private(set) var sortDirection = AppDefaults.timelineSortDirection {
|
private(set) var sortDirection = AppDefaults.timelineSortDirection {
|
||||||
didSet {
|
didSet {
|
||||||
|
@ -105,15 +106,24 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||||
|
|
||||||
var timelineFetcher: ArticleFetcher? {
|
var timelineFetcher: ArticleFetcher? {
|
||||||
didSet {
|
didSet {
|
||||||
|
|
||||||
currentArticleIndexPath = nil
|
currentArticleIndexPath = nil
|
||||||
if timelineFetcher is Feed {
|
if timelineFetcher is Feed {
|
||||||
showFeedNames = false
|
showFeedNames = false
|
||||||
} else {
|
} else {
|
||||||
showFeedNames = true
|
showFeedNames = true
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if isSearching {
|
||||||
|
fetchAndReplaceArticlesAsync {
|
||||||
|
self.masterTimelineViewController?.reinitializeArticles()
|
||||||
|
}
|
||||||
|
} else {
|
||||||
fetchAndReplaceArticlesSync()
|
fetchAndReplaceArticlesSync()
|
||||||
masterTimelineViewController?.reinitializeArticles()
|
masterTimelineViewController?.reinitializeArticles()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private(set) var showFeedNames = false
|
private(set) var showFeedNames = false
|
||||||
|
@ -506,12 +516,20 @@ class AppCoordinator: NSObject, UndoableCommandRunner, UnreadCountProvider {
|
||||||
|
|
||||||
func searchArticles(_ searchString: String) {
|
func searchArticles(_ searchString: String) {
|
||||||
guard !searchString.isEmpty else {
|
guard !searchString.isEmpty else {
|
||||||
|
isSearching = false
|
||||||
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
|
if let ip = currentMasterIndexPath, let node = nodeFor(ip), let fetcher = node.representedObject as? ArticleFetcher {
|
||||||
timelineFetcher = fetcher
|
timelineFetcher = fetcher
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
|
||||||
|
isSearching = true
|
||||||
|
|
||||||
|
if searchString.count < 3 {
|
||||||
|
timelineFetcher = nil
|
||||||
|
return
|
||||||
|
}
|
||||||
|
|
||||||
if searchString != lastSearchString {
|
if searchString != lastSearchString {
|
||||||
timelineFetcher = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString))
|
timelineFetcher = SmartFeed(delegate: SearchFeedDelegate(searchString: searchString))
|
||||||
lastSearchString = searchString
|
lastSearchString = searchString
|
||||||
|
@ -890,7 +908,7 @@ private extension AppCoordinator {
|
||||||
|
|
||||||
func emptyTheTimeline() {
|
func emptyTheTimeline() {
|
||||||
if !articles.isEmpty {
|
if !articles.isEmpty {
|
||||||
articles = [Article]()
|
replaceArticles(with: Set<Article>(), animate: true)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue