2021-09-28 23:01:49 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct Sidebar: View {
|
2021-10-16 22:48:58 +00:00
|
|
|
@EnvironmentObject<AccountsModel> private var accounts
|
2021-09-28 23:01:49 +00:00
|
|
|
@EnvironmentObject<NavigationModel> private var navigation
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
ScrollViewReader { scrollView in
|
|
|
|
List {
|
2021-10-17 23:06:00 +00:00
|
|
|
if !accounts.isEmpty {
|
|
|
|
mainNavigationLinks
|
2021-09-28 23:01:49 +00:00
|
|
|
|
2021-10-17 23:06:00 +00:00
|
|
|
AppSidebarRecents()
|
|
|
|
.id("recentlyOpened")
|
2021-09-28 23:01:49 +00:00
|
|
|
|
2021-10-17 23:06:00 +00:00
|
|
|
if accounts.signedIn {
|
|
|
|
AppSidebarSubscriptions()
|
|
|
|
AppSidebarPlaylists()
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
|
|
|
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
|
|
|
}
|
|
|
|
.listStyle(.sidebar)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var mainNavigationLinks: some View {
|
|
|
|
Section("Videos") {
|
|
|
|
NavigationLink(destination: LazyView(WatchNowView()), tag: TabSelection.watchNow, selection: $navigation.tabSelection) {
|
|
|
|
Label("Watch Now", systemImage: "play.circle")
|
|
|
|
.accessibility(label: Text("Watch Now"))
|
|
|
|
}
|
2021-10-20 22:21:50 +00:00
|
|
|
if accounts.app.supportsSubscriptions && accounts.signedIn {
|
2021-09-28 23:01:49 +00:00
|
|
|
NavigationLink(destination: LazyView(SubscriptionsView()), tag: TabSelection.subscriptions, selection: $navigation.tabSelection) {
|
|
|
|
Label("Subscriptions", systemImage: "star.circle")
|
|
|
|
.accessibility(label: Text("Subscriptions"))
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-10-20 22:21:50 +00:00
|
|
|
if accounts.app.supportsPopular {
|
|
|
|
NavigationLink(destination: LazyView(PopularView()), tag: TabSelection.popular, selection: $navigation.tabSelection) {
|
|
|
|
Label("Popular", systemImage: "chart.bar")
|
|
|
|
.accessibility(label: Text("Popular"))
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink(destination: LazyView(TrendingView()), tag: TabSelection.trending, selection: $navigation.tabSelection) {
|
|
|
|
Label("Trending", systemImage: "chart.line.uptrend.xyaxis")
|
|
|
|
.accessibility(label: Text("Trending"))
|
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
|
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.keyboardShortcut("f")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
|
|
|
|
if case .recentlyOpened = selection {
|
|
|
|
scrollView.scrollTo("recentlyOpened")
|
|
|
|
} else if case let .playlist(id) = selection {
|
|
|
|
scrollView.scrollTo(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|