mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
use searchTerm and selected labels to compute searchQuery
This commit is contained in:
parent
686b00bc4d
commit
0fa9526924
3 changed files with 23 additions and 8 deletions
|
|
@ -23,17 +23,17 @@ import Views
|
|||
viewModel.loadItems(dataService: dataService, isRefresh: true)
|
||||
}
|
||||
.searchable(
|
||||
text: $viewModel.searchQuery,
|
||||
text: $viewModel.searchTerm,
|
||||
placement: .sidebar
|
||||
) {
|
||||
if viewModel.searchQuery.isEmpty {
|
||||
if viewModel.searchTerm.isEmpty {
|
||||
Text("Inbox").searchCompletion("in:inbox ")
|
||||
Text("All").searchCompletion("in:all ")
|
||||
Text("Archived").searchCompletion("in:archive ")
|
||||
Text("Files").searchCompletion("type:file ")
|
||||
}
|
||||
}
|
||||
.onChange(of: viewModel.searchQuery) { _ in
|
||||
.onChange(of: viewModel.searchTerm) { _ in
|
||||
// Maybe we should debounce this, but
|
||||
// it feels like it works ok without
|
||||
viewModel.loadItems(dataService: dataService, isRefresh: true)
|
||||
|
|
|
|||
|
|
@ -77,17 +77,17 @@ import Views
|
|||
.listStyle(PlainListStyle())
|
||||
.navigationTitle("Home")
|
||||
.searchable(
|
||||
text: $viewModel.searchQuery,
|
||||
text: $viewModel.searchTerm,
|
||||
placement: .toolbar
|
||||
) {
|
||||
if viewModel.searchQuery.isEmpty {
|
||||
if viewModel.searchTerm.isEmpty {
|
||||
Text("Inbox").searchCompletion("in:inbox ")
|
||||
Text("All").searchCompletion("in:all ")
|
||||
Text("Archived").searchCompletion("in:archive ")
|
||||
Text("Files").searchCompletion("type:file ")
|
||||
}
|
||||
}
|
||||
.onChange(of: viewModel.searchQuery) { _ in
|
||||
.onChange(of: viewModel.searchTerm) { _ in
|
||||
// Maybe we should debounce this, but
|
||||
// it feels like it works ok without
|
||||
viewModel.loadItems(dataService: dataService, isRefresh: true)
|
||||
|
|
|
|||
|
|
@ -15,7 +15,8 @@ final class HomeFeedViewModel: ObservableObject {
|
|||
@Published var isLoading = false
|
||||
@Published var showPushNotificationPrimer = false
|
||||
@Published var itemUnderLabelEdit: FeedItem?
|
||||
@Published var searchQuery = ""
|
||||
@Published var searchTerm = ""
|
||||
@Published var selectedLabels = [FeedItemLabel]()
|
||||
@Published var snoozePresented = false
|
||||
@Published var itemToSnooze: FeedItem?
|
||||
@Published var selectedLinkItem: FeedItem?
|
||||
|
|
@ -68,7 +69,7 @@ final class HomeFeedViewModel: ObservableObject {
|
|||
dataService.libraryItemsPublisher(
|
||||
limit: 10,
|
||||
sortDescending: true,
|
||||
searchQuery: searchQuery.isEmpty ? nil : searchQuery,
|
||||
searchQuery: searchQuery,
|
||||
cursor: isRefresh ? nil : cursor
|
||||
)
|
||||
.sink(
|
||||
|
|
@ -195,4 +196,18 @@ final class HomeFeedViewModel: ObservableObject {
|
|||
items[index].labels = labels
|
||||
}
|
||||
}
|
||||
|
||||
private var searchQuery: String? {
|
||||
if searchTerm.isEmpty, selectedLabels.isEmpty {
|
||||
return nil
|
||||
}
|
||||
|
||||
var query = searchTerm
|
||||
|
||||
for label in selectedLabels {
|
||||
query.append(" label:\(label.name)")
|
||||
}
|
||||
|
||||
return query
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in a new issue