mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 21:43:41 +00:00
Simplify playlists view
This commit is contained in:
parent
713570dfd6
commit
15f3e11a78
@ -3,7 +3,7 @@ import Siesta
|
||||
import SwiftUI
|
||||
|
||||
struct ChannelPlaylistView: View {
|
||||
var playlist: ChannelPlaylist?
|
||||
var playlist: ChannelPlaylist
|
||||
var showCloseButton = false
|
||||
|
||||
@StateObject private var store = Store<ChannelPlaylist>()
|
||||
@ -19,15 +19,7 @@ struct ChannelPlaylistView: View {
|
||||
ContentItem.array(of: store.item?.videos ?? [])
|
||||
}
|
||||
|
||||
private var presentedPlaylist: ChannelPlaylist? {
|
||||
playlist ?? recents.presentedPlaylist
|
||||
}
|
||||
|
||||
private var resource: Resource? {
|
||||
guard let playlist = presentedPlaylist else {
|
||||
return nil
|
||||
}
|
||||
|
||||
let resource = accounts.api.channelPlaylist(playlist.id)
|
||||
resource?.addObserver(store)
|
||||
|
||||
@ -38,7 +30,6 @@ struct ChannelPlaylistView: View {
|
||||
VStack(alignment: .leading) {
|
||||
#if os(tvOS)
|
||||
HStack {
|
||||
if let playlist = presentedPlaylist {
|
||||
ThumbnailView(url: store.item?.thumbnailURL ?? playlist.thumbnailURL)
|
||||
.frame(width: 140, height: 80)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 2))
|
||||
@ -52,7 +43,6 @@ struct ChannelPlaylistView: View {
|
||||
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(accounts.app.appType.rawValue, playlist.id, playlist.title)))
|
||||
.labelStyle(.iconOnly)
|
||||
}
|
||||
|
||||
playButtons
|
||||
.labelStyle(.iconOnly)
|
||||
@ -63,9 +53,7 @@ struct ChannelPlaylistView: View {
|
||||
}
|
||||
.environment(\.listingStyle, channelPlaylistListingStyle)
|
||||
.onAppear {
|
||||
if let playlist = presentedPlaylist,
|
||||
let cache = ChannelPlaylistsCacheModel.shared.retrievePlaylist(playlist)
|
||||
{
|
||||
if let cache = ChannelPlaylistsCacheModel.shared.retrievePlaylist(playlist) {
|
||||
store.replace(cache)
|
||||
}
|
||||
resource?.loadIfNeeded()?.onSuccess { response in
|
||||
@ -111,15 +99,13 @@ struct ChannelPlaylistView: View {
|
||||
}
|
||||
}
|
||||
}
|
||||
.navigationTitle(label)
|
||||
.navigationTitle(playlist.title)
|
||||
#endif
|
||||
}
|
||||
|
||||
@ViewBuilder private var favoriteButton: some View {
|
||||
if let playlist = presentedPlaylist {
|
||||
FavoriteButton(item: FavoriteItem(section: .channelPlaylist(accounts.app.appType.rawValue, playlist.id, playlist.title)))
|
||||
}
|
||||
}
|
||||
|
||||
#if os(iOS)
|
||||
private var playlistMenu: some View {
|
||||
@ -140,13 +126,13 @@ struct ChannelPlaylistView: View {
|
||||
}
|
||||
} label: {
|
||||
HStack(spacing: 12) {
|
||||
if let url = store.item?.thumbnailURL ?? playlist?.thumbnailURL {
|
||||
if let url = store.item?.thumbnailURL ?? playlist.thumbnailURL {
|
||||
ThumbnailView(url: url)
|
||||
.frame(width: 60, height: 30)
|
||||
.clipShape(RoundedRectangle(cornerRadius: 2))
|
||||
}
|
||||
|
||||
Text(label)
|
||||
Text(playlist.title)
|
||||
.font(.headline)
|
||||
.foregroundColor(.primary)
|
||||
|
||||
@ -160,10 +146,6 @@ struct ChannelPlaylistView: View {
|
||||
}
|
||||
#endif
|
||||
|
||||
private var label: String {
|
||||
presentedPlaylist?.title ?? ""
|
||||
}
|
||||
|
||||
private var playlistButtonsPlacement: ToolbarItemPlacement {
|
||||
#if os(iOS)
|
||||
.navigationBarTrailing
|
||||
|
@ -7,6 +7,7 @@ struct AppTabNavigation: View {
|
||||
private var player = PlayerModel.shared
|
||||
@ObservedObject private var feed = FeedModel.shared
|
||||
@ObservedObject private var feedCount = UnwatchedFeedCountModel.shared
|
||||
private var recents = RecentsModel.shared
|
||||
|
||||
@Default(.showHome) private var showHome
|
||||
@Default(.showDocuments) private var showDocuments
|
||||
@ -189,9 +190,9 @@ struct AppTabNavigation: View {
|
||||
}
|
||||
|
||||
@ViewBuilder private var playlistView: some View {
|
||||
if navigation.presentingPlaylist {
|
||||
if navigation.presentingPlaylist, let playlist = recents.presentedPlaylist {
|
||||
NavigationView {
|
||||
ChannelPlaylistView(showCloseButton: true)
|
||||
ChannelPlaylistView(playlist: playlist, showCloseButton: true)
|
||||
}
|
||||
.environment(\.managedObjectContext, persistenceController.container.viewContext)
|
||||
.id("channelPlaylist")
|
||||
|
Loading…
Reference in New Issue
Block a user