2021-12-01 11:22:19 +00:00
|
|
|
import Defaults
|
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
|
2021-11-14 23:06:01 +00:00
|
|
|
@EnvironmentObject<PlaylistsModel> private var playlists
|
|
|
|
@EnvironmentObject<SubscriptionsModel> private var subscriptions
|
2021-09-28 23:01:49 +00:00
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
@Default(.visibleSections) private var visibleSections
|
|
|
|
|
2021-09-28 23:01:49 +00:00
|
|
|
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-11-14 23:06:01 +00:00
|
|
|
if accounts.api.signedIn {
|
2021-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions {
|
2021-11-14 23:06:01 +00:00
|
|
|
AppSidebarSubscriptions()
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
|
2021-11-14 23:06:01 +00:00
|
|
|
AppSidebarPlaylists()
|
|
|
|
}
|
2021-10-17 23:06:00 +00:00
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
}
|
2021-11-14 23:06:01 +00:00
|
|
|
.onAppear {
|
|
|
|
subscriptions.load()
|
|
|
|
playlists.load()
|
|
|
|
}
|
|
|
|
.onChange(of: accounts.signedIn) { _ in
|
|
|
|
subscriptions.load(force: true)
|
|
|
|
playlists.load(force: true)
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
.onChange(of: navigation.sidebarSectionChanged) { _ in
|
|
|
|
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
|
|
|
|
}
|
|
|
|
.listStyle(.sidebar)
|
|
|
|
}
|
2021-11-07 13:32:01 +00:00
|
|
|
.navigationTitle("Yattee")
|
|
|
|
#if os(iOS)
|
2021-11-07 16:52:42 +00:00
|
|
|
.navigationBarTitleDisplayMode(.inline)
|
2021-11-07 13:32:01 +00:00
|
|
|
#endif
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
var mainNavigationLinks: some View {
|
2021-11-28 14:37:55 +00:00
|
|
|
Section(header: Text("Videos")) {
|
2021-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.favorites) {
|
|
|
|
NavigationLink(destination: LazyView(FavoritesView()), tag: TabSelection.favorites, selection: $navigation.tabSelection) {
|
|
|
|
Label("Favorites", systemImage: "heart")
|
|
|
|
.accessibility(label: Text("Favorites"))
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
2021-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.subscriptions),
|
|
|
|
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-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.popular), accounts.app.supportsPopular {
|
2021-10-20 22:21:50 +00:00
|
|
|
NavigationLink(destination: LazyView(PopularView()), tag: TabSelection.popular, selection: $navigation.tabSelection) {
|
2021-11-28 14:37:55 +00:00
|
|
|
Label("Popular", systemImage: "arrow.up.right.circle")
|
2021-10-20 22:21:50 +00:00
|
|
|
.accessibility(label: Text("Popular"))
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
if visibleSections.contains(.trending) {
|
|
|
|
NavigationLink(destination: LazyView(TrendingView()), tag: TabSelection.trending, selection: $navigation.tabSelection) {
|
|
|
|
Label("Trending", systemImage: "chart.bar")
|
|
|
|
.accessibility(label: Text("Trending"))
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
|
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.keyboardShortcut("f")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 11:22:19 +00:00
|
|
|
private func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
|
2021-09-28 23:01:49 +00:00
|
|
|
if case .recentlyOpened = selection {
|
|
|
|
scrollView.scrollTo("recentlyOpened")
|
|
|
|
} else if case let .playlist(id) = selection {
|
|
|
|
scrollView.scrollTo(id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|