2021-12-01 16:52:19 +05:30
|
|
|
import Defaults
|
2021-09-29 04:31:49 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct Sidebar: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var accounts = AccountsModel.shared
|
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
2022-12-13 05:09:50 +05:30
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-17 02:56:14 +05:30
|
|
|
@ObservedObject private var feedCount = UnwatchedFeedCountModel.shared
|
2021-09-29 04:31:49 +05:30
|
|
|
|
2022-11-12 01:58:40 +05:30
|
|
|
@Default(.showHome) private var showHome
|
2021-12-01 16:52:19 +05:30
|
|
|
@Default(.visibleSections) private var visibleSections
|
2022-11-19 05:08:32 +05:30
|
|
|
#if os(iOS)
|
|
|
|
@Default(.showDocuments) private var showDocuments
|
|
|
|
#endif
|
2023-03-01 01:47:12 +05:30
|
|
|
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
2021-12-01 16:52:19 +05:30
|
|
|
|
2021-09-29 04:31:49 +05:30
|
|
|
var body: some View {
|
|
|
|
ScrollViewReader { scrollView in
|
|
|
|
List {
|
2022-11-11 04:25:39 +05:30
|
|
|
mainNavigationLinks
|
2021-09-29 04:31:49 +05:30
|
|
|
|
2022-11-11 04:25:39 +05:30
|
|
|
if !accounts.isEmpty {
|
2021-10-18 04:36:00 +05:30
|
|
|
AppSidebarRecents()
|
|
|
|
.id("recentlyOpened")
|
2021-09-29 04:31:49 +05:30
|
|
|
|
2021-11-15 04:36:01 +05:30
|
|
|
if accounts.api.signedIn {
|
2021-12-01 16:52:19 +05:30
|
|
|
if visibleSections.contains(.subscriptions), accounts.app.supportsSubscriptions {
|
2021-11-15 04:36:01 +05:30
|
|
|
AppSidebarSubscriptions()
|
|
|
|
}
|
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
if visibleSections.contains(.playlists), accounts.app.supportsUserPlaylists {
|
2021-11-15 04:36:01 +05:30
|
|
|
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)
|
|
|
|
}
|
2022-12-13 05:09:50 +05:30
|
|
|
.onAppear {
|
|
|
|
feed.calculateUnwatchedFeed()
|
|
|
|
}
|
|
|
|
.onChange(of: accounts.current) { _ in
|
|
|
|
feed.calculateUnwatchedFeed()
|
|
|
|
}
|
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")) {
|
2022-11-12 01:58:40 +05:30
|
|
|
if showHome {
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(HomeView()), tag: TabSelection.home, selection: $navigation.tabSelection) {
|
2022-11-09 19:04:04 +05:30
|
|
|
Label("Home", systemImage: "house")
|
|
|
|
.accessibility(label: Text("Home"))
|
2021-12-01 16:52:19 +05:30
|
|
|
}
|
2022-11-13 04:37:23 +05:30
|
|
|
.id("home")
|
2021-09-29 04:31:49 +05:30
|
|
|
}
|
2022-11-13 04:31:04 +05:30
|
|
|
|
|
|
|
#if os(iOS)
|
|
|
|
if showDocuments {
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(DocumentsView()), tag: TabSelection.documents, selection: $navigation.tabSelection) {
|
2022-11-13 04:31:04 +05:30
|
|
|
Label("Documents", systemImage: "folder")
|
|
|
|
.accessibility(label: Text("Documents"))
|
|
|
|
}
|
|
|
|
.id("documents")
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2022-11-12 01:58:40 +05:30
|
|
|
if !accounts.isEmpty {
|
|
|
|
if visibleSections.contains(.subscriptions),
|
|
|
|
accounts.app.supportsSubscriptions && accounts.signedIn
|
|
|
|
{
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(SubscriptionsView()), tag: TabSelection.subscriptions, selection: $navigation.tabSelection) {
|
2022-11-12 01:58:40 +05:30
|
|
|
Label("Subscriptions", systemImage: "star.circle")
|
|
|
|
.accessibility(label: Text("Subscriptions"))
|
|
|
|
}
|
2022-12-13 05:09:50 +05:30
|
|
|
.backport
|
2023-03-01 01:47:12 +05:30
|
|
|
.badge(showUnwatchedFeedBadges ? feedCount.unwatchedText : nil)
|
2022-12-14 22:40:01 +05:30
|
|
|
.contextMenu {
|
|
|
|
playUnwatchedButton
|
|
|
|
toggleWatchedButton
|
|
|
|
}
|
2022-11-12 01:58:40 +05:30
|
|
|
.id("subscriptions")
|
2021-09-29 04:31:49 +05:30
|
|
|
}
|
|
|
|
|
2022-11-12 01:58:40 +05:30
|
|
|
if visibleSections.contains(.popular), accounts.app.supportsPopular {
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(PopularView()), tag: TabSelection.popular, selection: $navigation.tabSelection) {
|
2022-11-12 01:58:40 +05:30
|
|
|
Label("Popular", systemImage: "arrow.up.right.circle")
|
|
|
|
.accessibility(label: Text("Popular"))
|
|
|
|
}
|
|
|
|
.id("popular")
|
2021-10-21 03:51:50 +05:30
|
|
|
}
|
2021-09-29 04:31:49 +05:30
|
|
|
|
2022-11-12 01:58:40 +05:30
|
|
|
if visibleSections.contains(.trending) {
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(TrendingView()), tag: TabSelection.trending, selection: $navigation.tabSelection) {
|
2022-11-12 01:58:40 +05:30
|
|
|
Label("Trending", systemImage: "chart.bar")
|
|
|
|
.accessibility(label: Text("Trending"))
|
|
|
|
}
|
|
|
|
.id("trending")
|
2021-12-01 16:52:19 +05:30
|
|
|
}
|
2021-09-29 04:31:49 +05:30
|
|
|
|
2022-12-18 00:05:07 +05:30
|
|
|
NavigationLink(destination: LazyView(SearchView()), tag: TabSelection.search, selection: $navigation.tabSelection) {
|
2022-11-12 01:04:20 +05:30
|
|
|
Label("Search", systemImage: "magnifyingglass")
|
|
|
|
.accessibility(label: Text("Search"))
|
|
|
|
}
|
|
|
|
.id("search")
|
|
|
|
.keyboardShortcut("f")
|
2021-09-29 04:31:49 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-12-14 22:40:01 +05:30
|
|
|
var playUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.playUnwatchedFeed()
|
|
|
|
} label: {
|
|
|
|
Label("Play all unwatched", systemImage: "play")
|
|
|
|
}
|
|
|
|
.disabled(!feed.canPlayUnwatchedFeed)
|
|
|
|
}
|
|
|
|
|
|
|
|
@ViewBuilder var toggleWatchedButton: some View {
|
|
|
|
if feed.canMarkAllFeedAsWatched {
|
|
|
|
markAllFeedAsWatchedButton
|
|
|
|
} else {
|
|
|
|
markAllFeedAsUnwatchedButton
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var markAllFeedAsWatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.markAllFeedAsWatched()
|
|
|
|
} label: {
|
|
|
|
Label("Mark all as watched", systemImage: "checkmark.circle.fill")
|
|
|
|
}
|
|
|
|
.disabled(!feed.canMarkAllFeedAsWatched)
|
|
|
|
}
|
|
|
|
|
|
|
|
var markAllFeedAsUnwatchedButton: some View {
|
|
|
|
Button {
|
|
|
|
feed.markAllFeedAsUnwatched()
|
|
|
|
} label: {
|
|
|
|
Label("Mark all as unwatched", systemImage: "checkmark.circle")
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-01 16:52:19 +05:30
|
|
|
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
|
|
|
}
|
|
|
|
}
|
2022-12-18 00:05:07 +05:30
|
|
|
|
|
|
|
struct Sidebar_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
Sidebar()
|
|
|
|
}
|
|
|
|
}
|