parent
0ad417e682
commit
8920cad499
@ -0,0 +1,48 @@ |
|||||||
|
import SwiftUI |
||||||
|
|
||||||
|
// Attaches a context menu matching the track table's right-click menu. |
||||||
|
// No-ops silently when track or config is nil so callers can pass optionals freely. |
||||||
|
struct TrackContextMenuModifier: ViewModifier { |
||||||
|
let track: Track? |
||||||
|
let config: TrackContextMenuConfig? |
||||||
|
|
||||||
|
func body(content: Content) -> some View { |
||||||
|
if let track, let config { |
||||||
|
content.contextMenu { |
||||||
|
if let lastPlaylistName = config.lastUsedPlaylistName, |
||||||
|
let onAddToLastPlaylist = config.onAddToLastPlaylist { |
||||||
|
Button("Add to \(lastPlaylistName)") { |
||||||
|
onAddToLastPlaylist(track) |
||||||
|
} |
||||||
|
Divider() |
||||||
|
} |
||||||
|
|
||||||
|
if !config.playlists.isEmpty { |
||||||
|
Menu("Add to Playlist") { |
||||||
|
ForEach(config.playlists) { playlist in |
||||||
|
Button(playlist.name) { |
||||||
|
config.onAddToPlaylist(track, playlist) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
if config.selectedPlaylist != nil, |
||||||
|
let onRemoveFromPlaylist = config.onRemoveFromPlaylist { |
||||||
|
Divider() |
||||||
|
Button("Remove from Playlist") { |
||||||
|
onRemoveFromPlaylist(track) |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
} else { |
||||||
|
content |
||||||
|
} |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
extension View { |
||||||
|
func trackContextMenu(track: Track?, config: TrackContextMenuConfig?) -> some View { |
||||||
|
modifier(TrackContextMenuModifier(track: track, config: config)) |
||||||
|
} |
||||||
|
} |
||||||
Loading…
Reference in new issue