2021-09-25 13:48:22 +05:30
|
|
|
import Defaults
|
2021-08-30 03:06:18 +05:30
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppSidebarSubscriptions: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
2022-12-13 17:44:20 +05:30
|
|
|
@ObservedObject private var feed = FeedModel.shared
|
2022-12-17 02:56:14 +05:30
|
|
|
@ObservedObject private var feedCount = UnwatchedFeedCountModel.shared
|
2022-12-11 20:45:42 +05:30
|
|
|
@ObservedObject private var subscriptions = SubscribedChannelsModel.shared
|
2022-12-13 17:44:20 +05:30
|
|
|
|
2023-03-01 01:47:12 +05:30
|
|
|
@Default(.showUnwatchedFeedBadges) private var showUnwatchedFeedBadges
|
2023-07-22 22:32:59 +05:30
|
|
|
@Default(.keepChannelsWithUnwatchedFeedOnTop) private var keepChannelsWithUnwatchedFeedOnTop
|
|
|
|
@Default(.showChannelAvatarInChannelsLists) private var showChannelAvatarInChannelsLists
|
|
|
|
|
|
|
|
@State private var channelLinkActive = false
|
|
|
|
@State private var channelForLink: Channel?
|
2023-03-01 01:47:12 +05:30
|
|
|
|
2021-08-30 03:06:18 +05:30
|
|
|
var body: some View {
|
|
|
|
Section(header: Text("Subscriptions")) {
|
2023-07-22 22:50:46 +05:30
|
|
|
ForEach(channels) { channel in
|
2021-09-29 04:31:49 +05:30
|
|
|
NavigationLink(tag: TabSelection.channel(channel.id), selection: $navigation.tabSelection) {
|
2022-12-18 00:05:07 +05:30
|
|
|
LazyView(ChannelVideosView(channel: channel))
|
2021-08-30 03:06:18 +05:30
|
|
|
} label: {
|
2022-12-13 17:44:20 +05:30
|
|
|
HStack {
|
2023-07-22 22:32:59 +05:30
|
|
|
if showChannelAvatarInChannelsLists {
|
2022-12-11 22:41:56 +05:30
|
|
|
ChannelAvatarView(channel: channel, subscribedBadge: false)
|
2022-12-16 03:11:42 +05:30
|
|
|
.frame(width: Constants.sidebarChannelThumbnailSize, height: Constants.sidebarChannelThumbnailSize)
|
2023-07-22 22:32:59 +05:30
|
|
|
|
2022-12-11 22:41:56 +05:30
|
|
|
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-17 02:56:14 +05:30
|
|
|
|
2022-12-19 00:09:03 +05:30
|
|
|
Spacer()
|
2022-12-11 22:41:56 +05:30
|
|
|
}
|
2023-07-22 22:32:59 +05:30
|
|
|
.lineLimit(1)
|
2023-03-01 01:47:12 +05:30
|
|
|
.badge(showUnwatchedFeedBadges ? feedCount.unwatchedByChannelText(channel) : nil)
|
2021-08-30 03:06:18 +05:30
|
|
|
}
|
|
|
|
.contextMenu {
|
|
|
|
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
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2023-07-22 22:50:46 +05:30
|
|
|
|
|
|
|
var channels: [Channel] {
|
|
|
|
keepChannelsWithUnwatchedFeedOnTop ? subscriptions.allByUnwatchedCount : subscriptions.all
|
|
|
|
}
|
2021-08-30 03:06:18 +05:30
|
|
|
}
|
2022-12-11 17:08:57 +05:30
|
|
|
|
|
|
|
struct AppSidebarSubscriptions_Previews: PreviewProvider {
|
|
|
|
static var previews: some View {
|
|
|
|
AppSidebarSubscriptions()
|
|
|
|
}
|
|
|
|
}
|