1
0
mirror of https://github.com/yattee/yattee.git synced 2024-12-13 13:50:32 +05:30

Refactor context menu

This commit is contained in:
Arkadiusz Fal 2022-12-19 00:09:54 +01:00
parent 441f3c9e80
commit 8ab42322fc
5 changed files with 39 additions and 36 deletions

View File

@ -30,6 +30,10 @@ private struct InNavigationViewKey: EnvironmentKey {
static let defaultValue = true
}
private struct InQueueListingKey: EnvironmentKey {
static let defaultValue = false
}
enum ListingStyle: String, CaseIterable, Defaults.Serializable {
case cells
case list
@ -103,4 +107,10 @@ extension EnvironmentValues {
get { self[InNavigationViewKey.self] }
set { self[InNavigationViewKey.self] = newValue }
}
var inQueueListing: Bool {
get { self[InQueueListingKey.self] }
set { self[InQueueListingKey.self] = newValue }
}
}

View File

@ -4,7 +4,6 @@ import SwiftUI
struct PlayerQueueView: View {
var sidebarQueue: Bool
@Binding var fullScreen: Bool
@FetchRequest(sortDescriptors: [.init(key: "watchedAt", ascending: false)])
var watches: FetchedResults<Watch>
@ -138,7 +137,7 @@ struct PlayerQueueView: View {
struct PlayerQueueView_Previews: PreviewProvider {
static var previews: some View {
VStack {
PlayerQueueView(sidebarQueue: true, fullScreen: .constant(true))
PlayerQueueView(sidebarQueue: true)
}
.injectFixtureEnvironmentObjects()
}

View File

@ -394,14 +394,14 @@ struct VideoPlayerView: View {
if !fullScreenPlayer {
#if os(iOS)
if sidebarQueue {
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
PlayerQueueView(sidebarQueue: true)
.frame(maxWidth: 350)
.background(colorScheme == .dark ? Color.black : Color.white)
.transition(.move(edge: .bottom))
}
#elseif os(macOS)
if Defaults[.playerSidebar] != .never {
PlayerQueueView(sidebarQueue: true, fullScreen: $fullScreenDetails)
PlayerQueueView(sidebarQueue: true)
.frame(width: 350)
.background(colorScheme == .dark ? Color.black : Color.white)
}

View File

@ -197,22 +197,9 @@ struct WatchNextView: View {
let queueForMoreVideos = player.queue.isEmpty ? [] : player.queue.suffix(from: model.isAutoplaying ? 1 : 0)
if !queueForMoreVideos.isEmpty {
ForEach(queueForMoreVideos) { item in
PlayerQueueRow(item: item)
.contextMenu {
removeButton(item)
removeAllButton()
if let video = item.video {
VideoContextMenuView(video: video)
}
}
#if os(tvOS)
.padding(.horizontal, 30)
#endif
#if !os(tvOS)
Divider()
#endif
ContentItemView(item: .init(video: item.video))
.environment(\.inQueueListing, true)
.environment(\.listingStyle, .list)
}
} else if player.playbackMode != .related && player.playbackMode != .loopOne {
Label(
@ -239,22 +226,6 @@ struct WatchNextView: View {
}
}
}
private func removeButton(_ item: PlayerQueueItem) -> some View {
Button {
player.remove(item)
} label: {
Label("Remove from the queue", systemImage: "trash")
}
}
private func removeAllButton() -> some View {
Button {
player.removeQueueItems()
} label: {
Label("Clear the queue", systemImage: "trash.fill")
}
}
}
struct WatchNextView_Previews: PreviewProvider {

View File

@ -8,6 +8,7 @@ struct VideoContextMenuView: View {
@Environment(\.inChannelView) private var inChannelView
@Environment(\.inChannelPlaylistView) private var inChannelPlaylistView
@Environment(\.inQueueListing) private var inQueueListing
@Environment(\.navigationStyle) private var navigationStyle
@Environment(\.currentPlaylistID) private var playlistID
@ -36,6 +37,12 @@ struct VideoContextMenuView: View {
}
@ViewBuilder var contextMenu: some View {
if inQueueListing {
if let item = player.queue.first(where: { $0.videoID == video.videoID }) {
removeFromQueueButton(item)
}
removeAllFromQueueButton()
}
if !video.localStreamIsDirectory {
if saveHistory {
Section {
@ -340,4 +347,20 @@ struct VideoContextMenuView: View {
Label("Remove from Playlist", systemImage: "text.badge.minus")
}
}
private func removeFromQueueButton(_ item: PlayerQueueItem) -> some View {
Button {
player.remove(item)
} label: {
Label("Remove from the queue", systemImage: "trash")
}
}
private func removeAllFromQueueButton() -> some View {
Button {
player.removeQueueItems()
} label: {
Label("Clear the queue", systemImage: "trash.fill")
}
}
}