show error toast when failing to add to playlist

This commit is contained in:
Drew Weymouth
2025-01-05 16:38:36 -08:00
parent 24364c590d
commit 7c657accc1
4 changed files with 27 additions and 1 deletions
+1
View File
@@ -17,6 +17,7 @@
"All": "All",
"All Tracks": "All Tracks",
"Alt. URL": "Alt. URL",
"An error occurred adding tracks to the playlist": "An error occurred adding tracks to the playlist",
"Are you sure you want to delete the server": "Are you sure you want to delete the server",
"Artist": "Artist",
"Artist (A-Z)": "Artist (A-Z)",
+1
View File
@@ -17,6 +17,7 @@
"All": "Todos",
"All Tracks": "Todas las pistas",
"Alt. URL": "URL alternativa",
"An error occurred adding tracks to the playlist": "Ha ocurrido un error al añadir pistas a la lista de reproducción",
"Are you sure you want to delete the server": "¿Estás seguro de que quieres eliminar el servidor?",
"Artist": "Artista",
"Artist (A-Z)": "Artista (A-Z)",
+16
View File
@@ -42,6 +42,7 @@ type CurPageFunc func() Route
type ToastProvider interface {
ShowSuccessToast(string)
ShowErrorToast(string)
}
type Controller struct {
@@ -310,6 +311,11 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
"Added tracks to playlist", n, map[string]string{"trackCount": strconv.Itoa(n)})
m.ToastProvider.ShowSuccessToast(msg)
}
notifyError := func() {
m.ToastProvider.ShowErrorToast(
lang.L("An error occurred adding tracks to the playlist"),
)
}
pop.Hide()
m.App.Config.Application.AddToPlaylistSkipDuplicates = sp.SkipDuplicates
if id == "" /* creating new playlist */ {
@@ -317,6 +323,9 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
err := m.App.ServerManager.Server.CreatePlaylist(sp.SearchDialog.SearchQuery(), trackIDs)
if err == nil {
notifySuccess(len(trackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}()
} else {
@@ -326,6 +335,7 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
currentTrackIDs := make(map[string]struct{})
if selectedPlaylist, err := m.App.ServerManager.Server.GetPlaylist(id); err != nil {
log.Printf("error getting playlist: %s", err.Error())
notifyError()
} else {
for _, track := range selectedPlaylist.Tracks {
currentTrackIDs[track.ID] = struct{}{}
@@ -337,6 +347,9 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
err := m.App.ServerManager.Server.AddPlaylistTracks(id, filterTrackIDs)
if err == nil {
notifySuccess(len(filterTrackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}
}()
@@ -345,6 +358,9 @@ func (m *Controller) DoAddTracksToPlaylistWorkflow(trackIDs []string) {
err := m.App.ServerManager.Server.AddPlaylistTracks(id, trackIDs)
if err == nil {
notifySuccess(len(trackIDs))
} else {
log.Println("error adding tracks to playlist: %s", err.Error())
notifyError()
}
}()
}
+9 -1
View File
@@ -39,9 +39,17 @@ func NewToastOverlay() *ToastOverlay {
}
func (t *ToastOverlay) ShowSuccessToast(message string) {
t.showToast(false, message)
}
func (t *ToastOverlay) ShowErrorToast(message string) {
t.showToast(true, message)
}
func (t *ToastOverlay) showToast(isErr bool, message string) {
t.cancelPreviousToast()
t.currentToast = newToast(false, message, t.dismissToast)
t.currentToast = newToast(isErr, message, t.dismissToast)
t.container.Objects = append(t.container.Objects, t.currentToast)
s := t.Size()