2021-07-11 20:52:49 +00:00
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppTabNavigation: View {
|
2021-08-31 21:17:50 +00:00
|
|
|
@EnvironmentObject<NavigationState> private var navigationState
|
2021-09-13 20:41:16 +00:00
|
|
|
@EnvironmentObject<SearchState> private var searchState
|
2021-09-19 11:06:54 +00:00
|
|
|
@EnvironmentObject<Recents> private var recents
|
|
|
|
|
2021-07-11 20:52:49 +00:00
|
|
|
var body: some View {
|
2021-08-31 21:17:50 +00:00
|
|
|
TabView(selection: $navigationState.tabSelection) {
|
2021-07-11 20:52:49 +00:00
|
|
|
NavigationView {
|
2021-09-18 20:36:42 +00:00
|
|
|
WatchNowView()
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2021-09-18 20:36:42 +00:00
|
|
|
Label("Watch Now", systemImage: "play.circle")
|
2021-07-11 20:52:49 +00:00
|
|
|
.accessibility(label: Text("Subscriptions"))
|
|
|
|
}
|
2021-09-18 20:36:42 +00:00
|
|
|
.tag(TabSelection.watchNow)
|
2021-07-11 20:52:49 +00:00
|
|
|
|
|
|
|
NavigationView {
|
2021-09-18 20:36:42 +00:00
|
|
|
SubscriptionsView()
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
2021-09-18 20:36:42 +00:00
|
|
|
Label("Subscriptions", systemImage: "star.circle.fill")
|
|
|
|
.accessibility(label: Text("Subscriptions"))
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
2021-09-18 20:36:42 +00:00
|
|
|
.tag(TabSelection.subscriptions)
|
|
|
|
|
|
|
|
// TODO: reenable with settings
|
|
|
|
// ============================
|
|
|
|
// NavigationView {
|
|
|
|
// PopularView()
|
|
|
|
// }
|
|
|
|
// .tabItem {
|
|
|
|
// Label("Popular", systemImage: "chart.bar")
|
|
|
|
// .accessibility(label: Text("Popular"))
|
|
|
|
// }
|
|
|
|
// .tag(TabSelection.popular)
|
2021-07-11 20:52:49 +00:00
|
|
|
|
|
|
|
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()
|
2021-09-19 12:42:47 +00:00
|
|
|
.searchable(text: $searchState.queryText, placement: .navigationBarDrawer(displayMode: .always)) {
|
2021-09-13 20:41:16 +00:00
|
|
|
ForEach(searchState.querySuggestions.collection, id: \.self) { suggestion in
|
|
|
|
Text(suggestion)
|
|
|
|
.searchCompletion(suggestion)
|
|
|
|
}
|
|
|
|
}
|
2021-09-19 12:42:47 +00:00
|
|
|
.onChange(of: searchState.queryText) { query in
|
2021-09-13 20:41:16 +00:00
|
|
|
searchState.loadQuerySuggestions(query)
|
|
|
|
}
|
|
|
|
.onSubmit(of: .search) {
|
|
|
|
searchState.changeQuery { query in
|
2021-09-19 12:42:47 +00:00
|
|
|
query.query = searchState.queryText
|
2021-09-13 20:41:16 +00:00
|
|
|
}
|
|
|
|
|
2021-09-19 12:42:47 +00:00
|
|
|
recents.open(RecentItem(from: searchState.queryText))
|
|
|
|
|
2021-09-13 20:41:16 +00:00
|
|
|
navigationState.tabSelection = .search
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|
|
|
|
.tabItem {
|
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.tag(TabSelection.search)
|
|
|
|
}
|
2021-09-19 12:42:47 +00:00
|
|
|
.environment(\.navigationStyle, .tab)
|
2021-08-31 21:17:50 +00:00
|
|
|
.sheet(isPresented: $navigationState.isChannelOpen, onDismiss: {
|
2021-09-19 11:06:54 +00:00
|
|
|
if let channel = recents.presentedChannel {
|
|
|
|
let recent = RecentItem(from: channel)
|
|
|
|
recents.close(recent)
|
|
|
|
}
|
2021-08-31 21:17:50 +00:00
|
|
|
}) {
|
2021-09-19 11:06:54 +00:00
|
|
|
if recents.presentedChannel != nil {
|
2021-08-31 21:17:50 +00:00
|
|
|
NavigationView {
|
2021-09-19 11:06:54 +00:00
|
|
|
ChannelVideosView(recents.presentedChannel!)
|
2021-08-31 21:17:50 +00:00
|
|
|
.environment(\.inNavigationView, true)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2021-07-11 20:52:49 +00:00
|
|
|
}
|