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