Skip to content

Commit

Permalink
show error toast when failing to add to playlist
Browse files Browse the repository at this point in the history
  • Loading branch information
dweymouth committed Jan 6, 2025
1 parent 24364c5 commit 7c657ac
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 1 deletion.
1 change: 1 addition & 0 deletions res/translations/en.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
1 change: 1 addition & 0 deletions res/translations/es.json
Original file line number Diff line number Diff line change
Expand Up @@ -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)",
Expand Down
16 changes: 16 additions & 0 deletions ui/controller/controller.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ type CurPageFunc func() Route

type ToastProvider interface {
ShowSuccessToast(string)
ShowErrorToast(string)
}

type Controller struct {
Expand Down Expand Up @@ -310,13 +311,21 @@ 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 */ {
go func() {
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 {
Expand All @@ -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{}{}
Expand All @@ -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()
}
}
}()
Expand All @@ -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()
}
}()
}
Expand Down
10 changes: 9 additions & 1 deletion ui/toastoverlay.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down

0 comments on commit 7c657ac

Please sign in to comment.