1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 22:00:31 +05:30
yattee/Shared/Navigation/Sidebar.swift

97 lines
3.7 KiB
Swift
Raw Normal View History

import Defaults
2021-09-29 04:31:49 +05:30
import SwiftUI
struct Sidebar: View {
2021-10-17 04:18:58 +05:30
@EnvironmentObject<AccountsModel> private var accounts
2021-09-29 04:31:49 +05:30
@EnvironmentObject<NavigationModel> private var navigation
@Default(.visibleSections) private var visibleSections
2021-09-29 04:31:49 +05:30
var body: some View {
ScrollViewReader { scrollView in
List {
2021-10-18 04:36:00 +05:30
if !accounts.isEmpty {
mainNavigationLinks
2021-09-29 04:31:49 +05:30
2021-10-18 04:36:00 +05:30
AppSidebarRecents()
.id("recentlyOpened")
2021-09-29 04:31:49 +05:30
if accounts.api.signedIn {
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions {
AppSidebarSubscriptions()
}
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
AppSidebarPlaylists()
}
2021-10-18 04:36:00 +05:30
}
2021-09-29 04:31:49 +05:30
}
}
.onChange(of: navigation.sidebarSectionChanged) { _ in
scrollScrollViewToItem(scrollView: scrollView, for: navigation.tabSelection)
}
.listStyle(.sidebar)
}
2021-11-07 19:02:01 +05:30
.navigationTitle("Yattee")
#if os(iOS)
2021-11-07 22:22:42 +05:30
.navigationBarTitleDisplayMode(.inline)
2021-11-07 19:02:01 +05:30
#endif
2021-09-29 04:31:49 +05:30
}
var mainNavigationLinks: some View {
2021-11-28 20:07:55 +05:30
Section(header: Text("Videos")) {
if visibleSections.contains(.favorites) {
NavigationLink(destination: LazyView(FavoritesView()), tag: TabSelection.favorites, selection: $navigation.tabSelection) {
Label("Favorites", systemImage: "heart")
.accessibility(label: Text("Favorites"))
}
2022-03-28 00:08:59 +05:30
.id("favorites")
2021-09-29 04:31:49 +05:30
}
if visibleSections.contains(.subscriptions),
accounts.app.supportsSubscriptions && accounts.signedIn
{
2021-09-29 04:31:49 +05:30
NavigationLink(destination: LazyView(SubscriptionsView()), tag: TabSelection.subscriptions, selection: $navigation.tabSelection) {
Label("Subscriptions", systemImage: "star.circle")
.accessibility(label: Text("Subscriptions"))
}
2022-03-28 00:08:59 +05:30
.id("subscriptions")
2021-09-29 04:31:49 +05:30
}
if visibleSections.contains(.popular), accounts.app.supportsPopular {
2021-10-21 03:51:50 +05:30
NavigationLink(destination: LazyView(PopularView()), tag: TabSelection.popular, selection: $navigation.tabSelection) {
2021-11-28 20:07:55 +05:30
Label("Popular", systemImage: "arrow.up.right.circle")
2021-10-21 03:51:50 +05:30
.accessibility(label: Text("Popular"))
}
2022-03-28 00:08:59 +05:30
.id("popular")
2021-09-29 04:31:49 +05:30
}
if visibleSections.contains(.trending) {
NavigationLink(destination: LazyView(TrendingView()), tag: TabSelection.trending, selection: $navigation.tabSelection) {
Label("Trending", systemImage: "chart.bar")
.accessibility(label: Text("Trending"))
}
2022-03-28 00:08:59 +05:30
.id("trending")
2021-09-29 04:31:49 +05:30
}
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
Label("Search", systemImage: "magnifyingglass")
.accessibility(label: Text("Search"))
}
2022-03-28 00:08:59 +05:30
.id("search")
2021-09-29 04:31:49 +05:30
.keyboardShortcut("f")
}
}
private func scrollScrollViewToItem(scrollView: ScrollViewProxy, for selection: TabSelection) {
2021-09-29 04:31:49 +05:30
if case .recentlyOpened = selection {
scrollView.scrollTo("recentlyOpened")
2022-03-28 00:08:59 +05:30
return
2021-09-29 04:31:49 +05:30
} else if case let .playlist(id) = selection {
scrollView.scrollTo(id)
2022-03-28 00:08:59 +05:30
return
2021-09-29 04:31:49 +05:30
}
2022-03-28 00:08:59 +05:30
scrollView.scrollTo(selection.stringValue)
2021-09-29 04:31:49 +05:30
}
}