chore: Improve 'Add to playlists' dialog
This commit is contained in:
+23
-39
@@ -322,49 +322,33 @@ func (m *Controller) PromptForFirstServer() {
|
||||
pop.Show()
|
||||
}
|
||||
|
||||
// Show dialog to prompt for playlist.
|
||||
// Show dialog to select playlist.
|
||||
// Depending on the results of that dialog, potentially create a new playlist
|
||||
// Add tracks to the user-specified playlist
|
||||
func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
|
||||
go func() {
|
||||
pls, err := m.App.ServerManager.Server.GetPlaylists()
|
||||
pls = sharedutil.FilterSlice(pls, func(pl *mediaprovider.Playlist) bool {
|
||||
return pl.Owner == m.App.ServerManager.LoggedInUser
|
||||
})
|
||||
if err != nil {
|
||||
// TODO: surface this error to user
|
||||
log.Printf("error getting user-owned playlists: %s", err.Error())
|
||||
return
|
||||
sp := dialogs.NewSelectPlaylistDialog(m.App.ServerManager.Server, m.App.ImageManager, m.App.ServerManager.LoggedInUser)
|
||||
pop := widget.NewModalPopUp(sp.SearchDialog, m.MainWindow.Canvas())
|
||||
sp.SetOnDismiss(func() {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
})
|
||||
sp.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string, query string) {
|
||||
pop.Hide()
|
||||
if id == "" {
|
||||
go m.App.ServerManager.Server.CreatePlaylist(query, trackIDs)
|
||||
} else {
|
||||
m.App.Config.Application.DefaultPlaylistID = id
|
||||
go m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
|
||||
}
|
||||
|
||||
selectedIdx := -1
|
||||
plNames := make([]string, 0, len(pls))
|
||||
for i, pl := range pls {
|
||||
plNames = append(plNames, pl.Name)
|
||||
if defId := m.App.Config.Application.DefaultPlaylistID; defId != "" && pl.ID == defId {
|
||||
selectedIdx = i
|
||||
}
|
||||
}
|
||||
|
||||
dlg := dialogs.NewAddToPlaylistDialog("Add to Playlist", plNames, selectedIdx)
|
||||
pop := widget.NewModalPopUp(dlg, m.MainWindow.Canvas())
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
dlg.OnCanceled = pop.Hide
|
||||
dlg.OnSubmit = func(playlistChoice int, newPlaylistName string) {
|
||||
pop.Hide()
|
||||
m.doModalClosed()
|
||||
if playlistChoice < 0 {
|
||||
go m.App.ServerManager.Server.CreatePlaylist(newPlaylistName, trackIDs)
|
||||
} else {
|
||||
playlist := pls[playlistChoice]
|
||||
m.App.Config.Application.DefaultPlaylistID = playlist.ID
|
||||
go m.App.ServerManager.Server.AddPlaylistTracks(
|
||||
playlist.ID, trackIDs)
|
||||
}
|
||||
}
|
||||
m.haveModal = true
|
||||
pop.Show()
|
||||
}()
|
||||
})
|
||||
m.ClosePopUpOnEscape(pop)
|
||||
m.haveModal = true
|
||||
min := sp.MinSize()
|
||||
height := fyne.Max(min.Height, fyne.Min(min.Height*1.5, m.MainWindow.Canvas().Size().Height*0.7))
|
||||
pop.Resize(fyne.NewSize(min.Width, height))
|
||||
pop.Show()
|
||||
m.MainWindow.Canvas().Focus(sp.GetSearchEntry())
|
||||
}
|
||||
|
||||
func (m *Controller) DoEditPlaylistWorkflow(playlist *mediaprovider.Playlist) {
|
||||
@@ -622,7 +606,7 @@ func (c *Controller) ShowQuickSearch() {
|
||||
pop.Hide()
|
||||
c.doModalClosed()
|
||||
})
|
||||
qs.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string) {
|
||||
qs.SetOnNavigateTo(func(contentType mediaprovider.ContentType, id string, query string) {
|
||||
pop.Hide()
|
||||
c.doModalClosed()
|
||||
switch contentType {
|
||||
|
||||
Reference in New Issue
Block a user