mirror of
https://github.com/yattee/yattee.git
synced 2025-08-06 10:44:06 +00:00
Search history for tab navigation
This commit is contained in:
@@ -20,8 +20,6 @@ struct AppSidebarNavigation: View {
|
||||
|
||||
@State private var didApplyPrimaryViewWorkAround = false
|
||||
|
||||
@State private var searchQuery = ""
|
||||
|
||||
var selection: Binding<TabSelection?> {
|
||||
navigationState.tabSelectionOptionalBinding
|
||||
}
|
||||
@@ -53,21 +51,22 @@ struct AppSidebarNavigation: View {
|
||||
|
||||
Text("Select section")
|
||||
}
|
||||
.searchable(text: $searchQuery, placement: .sidebar) {
|
||||
.environment(\.navigationStyle, .sidebar)
|
||||
.searchable(text: $searchState.queryText, placement: .sidebar) {
|
||||
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
||||
Text(suggestion)
|
||||
.searchCompletion(suggestion)
|
||||
}
|
||||
}
|
||||
.onChange(of: searchQuery) { query in
|
||||
.onChange(of: searchState.queryText) { query in
|
||||
searchState.loadQuerySuggestions(query)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
searchState.changeQuery { query in
|
||||
query.query = self.searchQuery
|
||||
query.query = searchState.queryText
|
||||
}
|
||||
|
||||
recents.open(RecentItem(type: .query, identifier: self.searchQuery, title: self.searchQuery))
|
||||
recents.open(RecentItem(from: searchState.queryText))
|
||||
|
||||
navigationState.tabSelection = .search
|
||||
}
|
||||
|
@@ -13,7 +13,7 @@ struct AppSidebarRecents: View {
|
||||
Group {
|
||||
if !recentItems.isEmpty {
|
||||
Section(header: Text("Recents")) {
|
||||
ForEach(recentItems) { recent in
|
||||
ForEach(recentItems.reversed()) { recent in
|
||||
Group {
|
||||
switch recent.type {
|
||||
case .channel:
|
||||
|
@@ -4,11 +4,8 @@ import SwiftUI
|
||||
struct AppTabNavigation: View {
|
||||
@EnvironmentObject<NavigationState> private var navigationState
|
||||
@EnvironmentObject<SearchState> private var searchState
|
||||
|
||||
@EnvironmentObject<Recents> private var recents
|
||||
|
||||
@State private var searchQuery = ""
|
||||
|
||||
var body: some View {
|
||||
TabView(selection: $navigationState.tabSelection) {
|
||||
NavigationView {
|
||||
@@ -60,20 +57,22 @@ struct AppTabNavigation: View {
|
||||
|
||||
NavigationView {
|
||||
SearchView()
|
||||
.searchable(text: $searchQuery, placement: .navigationBarDrawer(displayMode: .always)) {
|
||||
.searchable(text: $searchState.queryText, placement: .navigationBarDrawer(displayMode: .always)) {
|
||||
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
||||
Text(suggestion)
|
||||
.searchCompletion(suggestion)
|
||||
}
|
||||
}
|
||||
.onChange(of: searchQuery) { query in
|
||||
.onChange(of: searchState.queryText) { query in
|
||||
searchState.loadQuerySuggestions(query)
|
||||
}
|
||||
.onSubmit(of: .search) {
|
||||
searchState.changeQuery { query in
|
||||
query.query = self.searchQuery
|
||||
query.query = searchState.queryText
|
||||
}
|
||||
|
||||
recents.open(RecentItem(from: searchState.queryText))
|
||||
|
||||
navigationState.tabSelection = .search
|
||||
}
|
||||
}
|
||||
@@ -83,6 +82,7 @@ struct AppTabNavigation: View {
|
||||
}
|
||||
.tag(TabSelection.search)
|
||||
}
|
||||
.environment(\.navigationStyle, .tab)
|
||||
.sheet(isPresented: $navigationState.isChannelOpen, onDismiss: {
|
||||
if let channel = recents.presentedChannel {
|
||||
let recent = RecentItem(from: channel)
|
||||
|
Reference in New Issue
Block a user