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

83 lines
2.8 KiB
Swift
Raw Normal View History

2021-09-25 13:48:22 +05:30
import Defaults
2021-08-30 03:06:18 +05:30
import SwiftUI
struct AppSidebarSubscriptions: View {
@ObservedObject private var navigation = NavigationModel.shared
2022-12-13 17:44:20 +05:30
@ObservedObject private var feed = FeedModel.shared
2022-12-11 20:45:42 +05:30
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
2021-08-30 03:06:18 +05:30
2022-12-13 17:44:20 +05:30
@ObservedObject private var accounts = AccountsModel.shared
2021-08-30 03:06:18 +05:30
var body: some View {
Section(header: Text("Subscriptions")) {
ForEach(subscriptions.all) { channel in
2021-09-29 04:31:49 +05:30
NavigationLink(tag: TabSelection.channel(channel.id), selection: $navigation.tabSelection) {
2022-12-11 03:07:14 +05:30
LazyView(ChannelVideosView(channel: channel).modifier(PlayerOverlayModifier()))
2021-08-30 03:06:18 +05:30
} label: {
2022-12-13 17:44:20 +05:30
HStack {
if channel.thumbnailURL != nil {
2022-12-11 22:41:56 +05:30
ChannelAvatarView(channel: channel, subscribedBadge: false)
.frame(width: 20, height: 20)
Text(channel.name)
2022-12-13 17:44:20 +05:30
} else {
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
2022-12-11 22:41:56 +05:30
}
}
2022-12-13 17:44:20 +05:30
.backport
.badge(channelBadge(channel))
2021-08-30 03:06:18 +05:30
}
.contextMenu {
if subscriptions.isSubscribing(channel.id) {
toggleWatchedButton(channel)
}
2021-08-30 03:06:18 +05:30
Button("Unsubscribe") {
2022-06-25 04:51:05 +05:30
navigation.presentUnsubscribeAlert(channel, subscriptions: subscriptions)
2021-08-30 03:06:18 +05:30
}
}
2021-09-29 04:31:49 +05:30
.id("channel\(channel.id)")
2021-08-30 03:06:18 +05:30
}
}
}
2022-12-13 17:44:20 +05:30
func channelBadge(_ channel: Channel) -> Text? {
if let count = feed.unwatchedByChannel[accounts.current]?[channel.id] {
return Text(String(count))
}
return nil
}
@ViewBuilder func toggleWatchedButton(_ channel: Channel) -> some View {
if feed.canMarkChannelAsWatched(channel.id) {
markChannelAsWatchedButton(channel)
} else {
markChannelAsUnwatchedButton(channel)
}
}
func markChannelAsWatchedButton(_ channel: Channel) -> some View {
Button {
feed.markChannelAsWatched(channel.id)
} label: {
Label("Mark channel feed as watched", systemImage: "checkmark.circle.fill")
}
.disabled(!feed.canMarkAllFeedAsWatched)
}
func markChannelAsUnwatchedButton(_ channel: Channel) -> some View {
Button {
feed.markChannelAsUnwatched(channel.id)
} label: {
Label("Mark channel feed as unwatched", systemImage: "checkmark.circle")
}
}
2021-08-30 03:06:18 +05:30
}
struct AppSidebarSubscriptions_Previews: PreviewProvider {
static var previews: some View {
AppSidebarSubscriptions()
}
}