mirror of
https://github.com/yattee/yattee.git
synced 2024-11-10 08:18:19 +00:00
89 lines
2.9 KiB
Swift
89 lines
2.9 KiB
Swift
import Defaults
|
|
import SwiftUI
|
|
|
|
struct AppTabNavigation: View {
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
|
@EnvironmentObject<SearchState> private var searchState
|
|
|
|
@State private var searchQuery = ""
|
|
|
|
var body: some View {
|
|
TabView(selection: $navigationState.tabSelection) {
|
|
NavigationView {
|
|
SubscriptionsView()
|
|
}
|
|
.tabItem {
|
|
Label("Subscriptions", systemImage: "star.circle.fill")
|
|
.accessibility(label: Text("Subscriptions"))
|
|
}
|
|
.tag(TabSelection.subscriptions)
|
|
|
|
NavigationView {
|
|
PopularView()
|
|
}
|
|
.tabItem {
|
|
Label("Popular", systemImage: "chart.bar")
|
|
.accessibility(label: Text("Popular"))
|
|
}
|
|
.tag(TabSelection.popular)
|
|
|
|
NavigationView {
|
|
TrendingView()
|
|
}
|
|
.tabItem {
|
|
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
|
.accessibility(label: Text("Trending"))
|
|
}
|
|
.tag(TabSelection.trending)
|
|
|
|
NavigationView {
|
|
PlaylistsView()
|
|
}
|
|
.tabItem {
|
|
Label("Playlists", systemImage: "list.and.film")
|
|
.accessibility(label: Text("Playlists"))
|
|
}
|
|
.tag(TabSelection.playlists)
|
|
|
|
NavigationView {
|
|
SearchView()
|
|
.searchable(text: $searchQuery, placement: .navigationBarDrawer(displayMode: .always)) {
|
|
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
|
Text(suggestion)
|
|
.searchCompletion(suggestion)
|
|
}
|
|
}
|
|
.onChange(of: searchQuery) { query in
|
|
searchState.loadQuerySuggestions(query)
|
|
}
|
|
.onSubmit(of: .search) {
|
|
searchState.changeQuery { query in
|
|
query.query = self.searchQuery
|
|
}
|
|
|
|
navigationState.tabSelection = .search
|
|
}
|
|
}
|
|
.tabItem {
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
.accessibility(label: Text("Search"))
|
|
}
|
|
.tag(TabSelection.search)
|
|
}
|
|
.sheet(isPresented: $navigationState.isChannelOpen, onDismiss: {
|
|
navigationState.closeChannel(presentedChannel)
|
|
}) {
|
|
if presentedChannel != nil {
|
|
NavigationView {
|
|
ChannelVideosView(presentedChannel)
|
|
.environment(\.inNavigationView, true)
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
fileprivate var presentedChannel: Channel! {
|
|
navigationState.openChannels.first
|
|
}
|
|
}
|