mirror of
https://github.com/yattee/yattee.git
synced 2024-12-22 13:33:42 +00:00
Use menu for add to playlists
This commit is contained in:
parent
6b30e804c0
commit
b621eba236
@ -21,6 +21,10 @@ final class PlaylistsModel: ObservableObject {
|
||||
playlists.sorted { $0.title.lowercased() < $1.title.lowercased() }
|
||||
}
|
||||
|
||||
var editable: [Playlist] {
|
||||
all.filter(\.editable)
|
||||
}
|
||||
|
||||
var lastUsed: Playlist? {
|
||||
find(id: Defaults[.lastUsedPlaylistID])
|
||||
}
|
||||
@ -100,6 +104,7 @@ final class PlaylistsModel: ObservableObject {
|
||||
}
|
||||
) {
|
||||
self.load(force: true) {
|
||||
Defaults[.lastUsedPlaylistID] = playlistID
|
||||
self.reloadPlaylists.toggle()
|
||||
onSuccess()
|
||||
}
|
||||
|
@ -95,7 +95,7 @@ struct AddToPlaylistView: View {
|
||||
Text("Playlist")
|
||||
Menu {
|
||||
Picker("Playlist", selection: $selectedPlaylistID) {
|
||||
ForEach(editablePlaylists) { playlist in
|
||||
ForEach(model.editable) { playlist in
|
||||
Text(playlist.title).tag(playlist.id)
|
||||
}
|
||||
}
|
||||
@ -114,10 +114,6 @@ struct AddToPlaylistView: View {
|
||||
.padding(.horizontal)
|
||||
}
|
||||
|
||||
var editablePlaylists: [Playlist] {
|
||||
model.all.filter(\.editable)
|
||||
}
|
||||
|
||||
private var formAlignment: HorizontalAlignment {
|
||||
#if os(tvOS)
|
||||
.trailing
|
||||
@ -146,10 +142,10 @@ struct AddToPlaylistView: View {
|
||||
return // swiftlint:disable:this implicit_return
|
||||
}
|
||||
|
||||
selectedPlaylistID = editablePlaylists.next(after: selectedPlaylist!)!.id
|
||||
selectedPlaylistID = model.editable.next(after: selectedPlaylist!)!.id
|
||||
}
|
||||
.contextMenu {
|
||||
ForEach(editablePlaylists) { playlist in
|
||||
ForEach(model.editable) { playlist in
|
||||
Button(playlist.title) {
|
||||
selectedPlaylistID = playlist.id
|
||||
}
|
||||
@ -161,11 +157,7 @@ struct AddToPlaylistView: View {
|
||||
#endif
|
||||
|
||||
private func addToPlaylist() {
|
||||
guard let id = selectedPlaylist?.id else {
|
||||
return
|
||||
}
|
||||
|
||||
Defaults[.lastUsedPlaylistID] = id
|
||||
guard let id = selectedPlaylist?.id else { return }
|
||||
|
||||
model.addVideo(playlistID: id, videoID: video.videoID)
|
||||
|
||||
|
@ -72,7 +72,11 @@ struct VideoContextMenuView: View {
|
||||
|
||||
if accounts.app.supportsUserPlaylists, accounts.signedIn, !video.isLocal {
|
||||
Section {
|
||||
#if os(tvOS)
|
||||
addToPlaylistButton
|
||||
#else
|
||||
addToPlaylistMenu
|
||||
#endif
|
||||
addToLastPlaylistButton
|
||||
|
||||
if let id = navigation.tabSelection?.playlistID ?? playlistID {
|
||||
@ -309,6 +313,26 @@ struct VideoContextMenuView: View {
|
||||
}
|
||||
}
|
||||
|
||||
#if !os(tvOS)
|
||||
@ViewBuilder private var addToPlaylistMenu: some View {
|
||||
if playlists.playlists.isEmpty {
|
||||
Text("No Playlists")
|
||||
} else {
|
||||
Menu {
|
||||
ForEach(playlists.editable) { playlist in
|
||||
Button {
|
||||
playlists.addVideo(playlistID: playlist.id, videoID: video.videoID)
|
||||
} label: {
|
||||
Text(playlist.title).tag(playlist.id)
|
||||
}
|
||||
}
|
||||
} label: {
|
||||
Label("Add to Playlist...", systemImage: "text.badge.plus")
|
||||
}
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
func removeFromPlaylistButton(playlistID: String) -> some View {
|
||||
Button {
|
||||
playlists.removeVideo(index: video.indexID!, playlistID: playlistID)
|
||||
|
Loading…
Reference in New Issue
Block a user