1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-15 14:50:32 +05:30
yattee/Shared/Subscriptions/SubscriptionsView.swift

155 lines
4.6 KiB
Swift
Raw Normal View History

import Defaults
2022-12-16 14:05:10 +05:30
import Siesta
2022-12-10 07:31:59 +05:30
import SwiftUI
struct SubscriptionsView: View {
enum Page: String, CaseIterable, Defaults.Serializable {
case feed
case channels
2022-12-10 07:31:59 +05:30
}
@Default(.subscriptionsViewPage) private var subscriptionsViewPage
2022-12-12 05:48:29 +05:30
@Default(.subscriptionsListingStyle) private var subscriptionsListingStyle
2022-12-13 05:09:50 +05:30
@ObservedObject private var feed = FeedModel.shared
2022-12-16 14:05:10 +05:30
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
2022-12-13 05:09:50 +05:30
2022-12-10 07:31:59 +05:30
var body: some View {
2022-12-11 03:07:14 +05:30
SignInRequiredView(title: "Subscriptions".localized()) {
switch subscriptionsViewPage {
case .feed:
FeedView()
case .channels:
ChannelsView()
#if os(tvOS)
.ignoresSafeArea(.all, edges: .horizontal)
#endif
}
}
2022-12-12 05:48:29 +05:30
.environment(\.listingStyle, subscriptionsListingStyle)
#if os(iOS)
2022-12-12 05:48:29 +05:30
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
2023-05-25 20:43:01 +05:30
HStack {
Picker("Page", selection: $subscriptionsViewPage) {
Label("Feed", systemImage: "film").tag(Page.feed)
Label("Channels", systemImage: "person.3.fill").tag(Page.channels)
}
.pickerStyle(.segmented)
.labelStyle(.titleOnly)
2023-05-25 20:43:01 +05:30
subscriptionsMenu
}
.frame(maxWidth: 500)
2022-12-12 05:48:29 +05:30
}
2022-12-16 14:05:10 +05:30
ToolbarItem {
RequestErrorButton(error: requestError)
}
2022-12-12 05:48:29 +05:30
}
#endif
#if os(macOS)
.toolbar {
2023-04-22 21:29:28 +05:30
ToolbarItemGroup {
2022-12-12 05:48:29 +05:30
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
HideWatchedButtons()
2023-05-23 22:24:53 +05:30
HideShortsButtons()
2022-12-13 17:44:20 +05:30
toggleWatchedButton
2023-04-22 21:29:28 +05:30
.id(feed.watchedId)
2022-12-14 03:02:49 +05:30
playUnwatchedButton
2023-04-22 21:29:28 +05:30
.id(feed.watchedId)
2022-12-14 03:02:49 +05:30
}
}
#endif
}
2022-12-11 01:38:03 +05:30
2022-12-16 14:05:10 +05:30
var requestError: RequestError? {
subscriptionsViewPage == .channels ? subscriptions.error : feed.error
}
#if os(iOS)
var subscriptionsMenu: some View {
Menu {
2022-12-12 05:48:29 +05:30
if subscriptionsViewPage == .feed {
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
Section {
HideWatchedButtons()
HideShortsButtons()
}
2023-02-25 21:12:18 +05:30
playUnwatchedButton
2022-12-13 17:44:20 +05:30
toggleWatchedButton
}
2022-12-13 17:44:20 +05:30
2022-12-12 03:45:56 +05:30
Section {
SettingsButtons()
}
} label: {
HStack(spacing: 12) {
Image(systemName: "chevron.down.circle.fill")
.foregroundColor(.accentColor)
2023-05-25 20:43:01 +05:30
.imageScale(.large)
2022-12-10 07:31:59 +05:30
}
.transaction { t in t.animation = nil }
2022-12-10 07:31:59 +05:30
}
}
2022-12-12 04:10:08 +05:30
var menuLabel: some View {
HStack {
Image(systemName: subscriptionsViewPage == .channels ? "person.3.fill" : "film")
2022-12-12 05:48:29 +05:30
.imageScale(.small)
2022-12-12 04:10:08 +05:30
Text(subscriptionsViewPage.rawValue.capitalized.localized())
.font(.headline)
}
2022-12-10 07:31:59 +05:30
}
#endif
2022-12-13 17:44:20 +05:30
var playUnwatchedButton: some View {
Button {
feed.playUnwatchedFeed()
} label: {
Label("Play all unwatched", systemImage: "play")
}
2024-02-26 18:42:11 +05:30
.help("Play all unwatched")
2022-12-13 17:44:20 +05:30
.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")
}
2024-02-26 18:42:11 +05:30
.help("Mark all as watched")
2022-12-13 17:44:20 +05:30
.disabled(!feed.canMarkAllFeedAsWatched)
}
var markAllFeedAsUnwatchedButton: some View {
Button {
feed.markAllFeedAsUnwatched()
} label: {
Label("Mark all as unwatched", systemImage: "checkmark.circle")
}
2024-02-26 18:42:11 +05:30
.help("Mark all as unwatched")
2022-12-13 17:44:20 +05:30
}
2022-12-10 07:31:59 +05:30
}
struct SubscriptionsView_Previews: PreviewProvider {
2022-12-10 07:31:59 +05:30
static var previews: some View {
NavigationView {
SubscriptionsView()
}
2022-12-10 07:31:59 +05:30
}
}