mirror of
https://github.com/nicoverbruggen/phpmon.git
synced 2025-08-08 04:20:07 +02:00
👌 Add debounce to site search (#82)
This commit is contained in:
@@ -172,13 +172,17 @@ class SiteListVC: NSViewController, NSTableViewDelegate, NSTableViewDataSource {
|
||||
|
||||
if searchString.isEmpty {
|
||||
sites = Valet.shared.sites
|
||||
tableView.reloadData()
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
return
|
||||
}
|
||||
|
||||
sites = Valet.shared.sites.filter({ site in
|
||||
return site.name.lowercased().contains(searchString)
|
||||
})
|
||||
|
||||
DispatchQueue.main.async {
|
||||
self.tableView.reloadData()
|
||||
}
|
||||
|
@@ -34,12 +34,18 @@ class SiteListWC: PMWindowController, NSSearchFieldDelegate, NSToolbarDelegate {
|
||||
return self.contentViewController as! SiteListVC
|
||||
}
|
||||
|
||||
var searchTimer: Timer?
|
||||
|
||||
func controlTextDidChange(_ notification: Notification) {
|
||||
guard let searchField = notification.object as? NSSearchField else {
|
||||
return
|
||||
}
|
||||
|
||||
contentVC.searchedFor(text: searchField.stringValue)
|
||||
self.searchTimer?.invalidate()
|
||||
|
||||
searchTimer = Timer.scheduledTimer(withTimeInterval: 0.3, repeats: false, block: { _ in
|
||||
self.contentVC.searchedFor(text: searchField.stringValue)
|
||||
})
|
||||
}
|
||||
|
||||
// MARK: - Reload functionality
|
||||
|
Reference in New Issue
Block a user