2021-09-19 16:36:54 +05:30
|
|
|
import Defaults
|
|
|
|
import SwiftUI
|
|
|
|
|
|
|
|
struct AppSidebarRecents: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
var recents = RecentsModel.shared
|
2021-09-19 16:36:54 +05:30
|
|
|
|
|
|
|
@Default(.recentlyOpened) private var recentItems
|
|
|
|
|
|
|
|
var body: some View {
|
|
|
|
Group {
|
|
|
|
if !recentItems.isEmpty {
|
|
|
|
Section(header: Text("Recents")) {
|
2021-09-19 18:12:47 +05:30
|
|
|
ForEach(recentItems.reversed()) { recent in
|
2021-09-19 16:36:54 +05:30
|
|
|
Group {
|
|
|
|
switch recent.type {
|
|
|
|
case .channel:
|
2021-09-29 04:31:49 +05:30
|
|
|
RecentNavigationLink(recent: recent) {
|
2022-12-18 00:05:07 +05:30
|
|
|
LazyView(ChannelVideosView(channel: recent.channel!))
|
2021-09-19 16:36:54 +05:30
|
|
|
}
|
2021-10-23 04:34:03 +05:30
|
|
|
|
|
|
|
case .playlist:
|
|
|
|
RecentNavigationLink(recent: recent, systemImage: "list.and.film") {
|
2022-12-18 00:05:07 +05:30
|
|
|
LazyView(ChannelPlaylistView(playlist: recent.playlist!))
|
2021-10-23 04:34:03 +05:30
|
|
|
}
|
|
|
|
|
2021-09-19 16:36:54 +05:30
|
|
|
case .query:
|
2021-09-29 04:31:49 +05:30
|
|
|
RecentNavigationLink(recent: recent, systemImage: "magnifyingglass") {
|
2022-12-18 00:05:07 +05:30
|
|
|
LazyView(SearchView(recent.query!))
|
2021-09-19 16:36:54 +05:30
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.contextMenu {
|
|
|
|
Button("Clear All Recents") {
|
|
|
|
recents.clear()
|
|
|
|
}
|
|
|
|
|
|
|
|
Button("Clear Search History") {
|
|
|
|
recents.clearQueries()
|
|
|
|
}
|
|
|
|
.disabled(!recentItems.contains { $0.type == .query })
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
struct RecentNavigationLink<DestinationContent: View>: View {
|
2022-11-25 02:06:05 +05:30
|
|
|
var recents = RecentsModel.shared
|
|
|
|
@ObservedObject private var navigation = NavigationModel.shared
|
2021-09-19 16:36:54 +05:30
|
|
|
|
2023-07-22 22:32:59 +05:30
|
|
|
@Default(.showChannelAvatarInChannelsLists) private var showChannelAvatarInChannelsLists
|
|
|
|
|
2021-09-19 16:36:54 +05:30
|
|
|
var recent: RecentItem
|
|
|
|
var systemImage: String?
|
|
|
|
let destination: DestinationContent
|
|
|
|
|
|
|
|
init(
|
|
|
|
recent: RecentItem,
|
|
|
|
systemImage: String? = nil,
|
|
|
|
@ViewBuilder destination: () -> DestinationContent
|
|
|
|
) {
|
|
|
|
self.recent = recent
|
|
|
|
self.systemImage = systemImage
|
|
|
|
self.destination = destination()
|
|
|
|
}
|
|
|
|
|
|
|
|
var body: some View {
|
2021-09-29 04:31:49 +05:30
|
|
|
NavigationLink(tag: TabSelection.recentlyOpened(recent.tag), selection: $navigation.tabSelection) {
|
2021-09-19 16:36:54 +05:30
|
|
|
destination
|
|
|
|
} label: {
|
|
|
|
HStack {
|
2022-12-14 22:40:50 +05:30
|
|
|
if recent.type == .channel,
|
|
|
|
let channel = recent.channel,
|
2023-07-22 22:32:59 +05:30
|
|
|
showChannelAvatarInChannelsLists
|
2022-12-14 22:40:50 +05:30
|
|
|
{
|
|
|
|
ChannelAvatarView(channel: channel, subscribedBadge: false)
|
2023-07-22 22:32:59 +05:30
|
|
|
.id("channel-avatar-\(channel.id)")
|
2022-12-16 03:11:42 +05:30
|
|
|
.frame(width: Constants.sidebarChannelThumbnailSize, height: Constants.sidebarChannelThumbnailSize)
|
2022-12-14 22:40:50 +05:30
|
|
|
|
|
|
|
Text(channel.name)
|
|
|
|
} else {
|
|
|
|
Label(recent.title, systemImage: labelSystemImage)
|
|
|
|
.lineLimit(1)
|
|
|
|
}
|
2021-09-19 16:36:54 +05:30
|
|
|
|
|
|
|
Spacer()
|
|
|
|
|
|
|
|
Button(action: {
|
|
|
|
recents.close(recent)
|
|
|
|
}) {
|
|
|
|
Image(systemName: "xmark.circle.fill")
|
|
|
|
}
|
|
|
|
.foregroundColor(.secondary)
|
2021-10-22 04:59:10 +05:30
|
|
|
.opacity(0.5)
|
2021-09-19 16:36:54 +05:30
|
|
|
.buttonStyle(.plain)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
.id(recent.tag)
|
|
|
|
}
|
|
|
|
|
|
|
|
var labelSystemImage: String {
|
2022-01-06 22:25:56 +05:30
|
|
|
systemImage != nil ? systemImage! : RecentsModel.symbolSystemImage(recent.title)
|
2021-09-19 16:36:54 +05:30
|
|
|
}
|
|
|
|
}
|