2021-09-25 08:18:22 +00:00
|
|
|
import Defaults
|
2021-08-29 21:36:18 +00:00
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppSidebarSubscriptions: View {
|
2022-11-24 20:36:05 +00:00
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
2022-12-13 12:14:20 +00:00
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-16 21:26:14 +00:00
|
|
|
@ObservedObject private var feedCount = UnwatchedFeedCountModel.shared
|
2022-12-11 15:15:42 +00:00
|
|
|
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
2022-12-13 12:14:20 +00:00
|
|
|
|
2023-02-28 20:17:12 +00:00
|
|
|
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
2023-07-22 17:02:59 +00:00
|
|
|
@Default(.keepChannelsWithUnwatchedFeedOnTop) private var keepChannelsWithUnwatchedFeedOnTop
|
|
|
|
@Default(.showChannelAvatarInChannelsLists) private var showChannelAvatarInChannelsLists
|
|
|
|
|
|
|
|
@State private var channelLinkActive = false
|
|
|
|
@State private var channelForLink: Channel?
|
2023-02-28 20:17:12 +00:00
|
|
|
|
2021-08-29 21:36:18 +00:00
|
|
|
var body: some View {
|
|
|
|
Section(header: Text("Subscriptions")) {
|
2023-07-22 17:20:46 +00:00
|
|
|
ForEach(channels) { channel in
|
2021-09-28 23:01:49 +00:00
|
|
|
NavigationLink(tag: TabSelection.channel(channel.id), selection: $navigation.tabSelection) {
|
2022-12-17 18:35:07 +00:00
|
|
|
LazyView(ChannelVideosView(channel: channel))
|
2021-08-29 21:36:18 +00:00
|
|
|
} label: {
|
2022-12-13 12:14:20 +00:00
|
|
|
HStack {
|
2023-07-22 17:02:59 +00:00
|
|
|
if showChannelAvatarInChannelsLists {
|
2022-12-11 17:11:56 +00:00
|
|
|
ChannelAvatarView(channel: channel, subscribedBadge: false)
|
2022-12-15 21:41:42 +00:00
|
|
|
.frame(width: Constants.sidebarChannelThumbnailSize, height: Constants.sidebarChannelThumbnailSize)
|
2023-07-22 17:02:59 +00:00
|
|
|
|
2022-12-11 17:11:56 +00:00
|
|
|
Text(channel.name)
|
2022-12-13 12:14:20 +00:00
|
|
|
} else {
|
|
|
|
Label(channel.name, systemImage: RecentsModel.symbolSystemImage(channel.name))
|
2022-12-11 17:11:56 +00:00
|
|
|
}
|
2022-12-16 21:26:14 +00:00
|
|
|
|
2022-12-18 18:39:03 +00:00
|
|
|
Spacer()
|
2022-12-11 17:11:56 +00:00
|
|
|
}
|
2023-07-22 17:02:59 +00:00
|
|
|
.lineLimit(1)
|
2023-02-28 20:17:12 +00:00
|
|
|
.badge(showUnwatchedFeedBadges ? feedCount.unwatchedByChannelText(channel) : nil)
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
|
|
|
.contextMenu {
|
|
|
|
Button("Unsubscribe") {
|
2022-06-24 23:21:05 +00:00
|
|
|
navigation.presentUnsubscribeAlert(channel, subscriptions: subscriptions)
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
2021-09-28 23:01:49 +00:00
|
|
|
.id("channel\(channel.id)")
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-22 17:20:46 +00:00
|
|
|
|
|
|
|
var channels: [Channel] {
|
|
|
|
keepChannelsWithUnwatchedFeedOnTop ? subscriptions.allByUnwatchedCount : subscriptions.all
|
|
|
|
}
|
2021-08-29 21:36:18 +00:00
|
|
|
}
|
2022-12-11 11:38:57 +00:00
|
|
|
|
|
|
|
struct AppSidebarSubscriptions_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AppSidebarSubscriptions()
|
|
|
|
}
|
|
|
|
}
|