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

148 lines
4.1 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)
2022-12-10 07:31:59 +05:30
#if os(iOS)
2022-12-12 05:48:29 +05:30
.navigationBarTitleDisplayMode(.inline)
.toolbar {
ToolbarItem(placement: .principal) {
subscriptionsMenu
}
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 {
2022-12-12 05:48:29 +05:30
ToolbarItem {
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
}
2022-12-13 17:44:20 +05:30
ToolbarItem {
toggleWatchedButton
}
2022-12-14 03:02:49 +05:30
ToolbarItem {
playUnwatchedButton
}
}
#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 {
Picker("Page", selection: $subscriptionsViewPage) {
Label("Feed", systemImage: "film").tag(Page.feed)
Label("Channels", systemImage: "person.3.fill").tag(Page.channels)
2022-12-10 07:31:59 +05:30
}
2022-12-12 03:45:56 +05:30
2022-12-12 05:48:29 +05:30
if subscriptionsViewPage == .feed {
ListingStyleButtons(listingStyle: $subscriptionsListingStyle)
}
2022-12-13 17:44:20 +05:30
playUnwatchedButton
toggleWatchedButton
2022-12-12 03:45:56 +05:30
Section {
SettingsButtons()
}
} label: {
HStack(spacing: 12) {
2022-12-12 04:10:08 +05:30
menuLabel
.foregroundColor(.primary)
Image(systemName: "chevron.down.circle.fill")
.foregroundColor(.accentColor)
.imageScale(.small)
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")
}
.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")
}
}
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
}
}