From 67af2cc6a9f41567b4c3441b08f4a94732e5d664 Mon Sep 17 00:00:00 2001 From: chme Date: Sun, 23 Dec 2018 09:54:02 +0100 Subject: [PATCH] [web-src] Refactor showing notification after queue add action --- web-src/src/components/ModalDialogAlbum.vue | 8 ++------ web-src/src/components/ModalDialogArtist.vue | 8 ++------ web-src/src/components/ModalDialogGenre.vue | 8 ++------ web-src/src/components/ModalDialogPlaylist.vue | 8 ++------ web-src/src/components/ModalDialogTrack.vue | 8 ++------ .../src/components/SpotifyModalDialogAlbum.vue | 8 ++------ .../src/components/SpotifyModalDialogArtist.vue | 8 ++------ .../components/SpotifyModalDialogPlaylist.vue | 8 ++------ .../src/components/SpotifyModalDialogTrack.vue | 8 ++------ web-src/src/webapi/index.js | 16 ++++++++++++---- 10 files changed, 30 insertions(+), 58 deletions(-) diff --git a/web-src/src/components/ModalDialogAlbum.vue b/web-src/src/components/ModalDialogAlbum.vue index a3480998..760fbc79 100644 --- a/web-src/src/components/ModalDialogAlbum.vue +++ b/web-src/src/components/ModalDialogAlbum.vue @@ -76,16 +76,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.album.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.album.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.album.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.album.uri) }, open_album: function () { diff --git a/web-src/src/components/ModalDialogArtist.vue b/web-src/src/components/ModalDialogArtist.vue index 291f3edc..8ec4bd93 100644 --- a/web-src/src/components/ModalDialogArtist.vue +++ b/web-src/src/components/ModalDialogArtist.vue @@ -54,16 +54,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.artist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Artist tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.artist.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.artist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.artist.uri) }, open_artist: function () { diff --git a/web-src/src/components/ModalDialogGenre.vue b/web-src/src/components/ModalDialogGenre.vue index 249ca9bd..974b3681 100644 --- a/web-src/src/components/ModalDialogGenre.vue +++ b/web-src/src/components/ModalDialogGenre.vue @@ -47,18 +47,14 @@ export default { queue_add: function () { this.$emit('close') webapi.library_genre(this.genre.name).then(({ data }) => - webapi.queue_add(data.albums.items.map(a => a.uri).join(',')).then(() => - this.$store.dispatch('add_notification', { text: 'Genre albums appended to queue', type: 'info', timeout: 1500 }) - ) + webapi.queue_add(data.albums.items.map(a => a.uri).join(',')) ) }, queue_add_next: function () { this.$emit('close') webapi.library_genre(this.genre.name).then(({ data }) => - webapi.queue_add_next(data.albums.items.map(a => a.uri).join(',')).then(() => - this.$store.dispatch('add_notification', { text: 'Genre albums playing next', type: 'info', timeout: 1500 }) - ) + webapi.queue_add_next(data.albums.items.map(a => a.uri).join(',')) ) }, diff --git a/web-src/src/components/ModalDialogPlaylist.vue b/web-src/src/components/ModalDialogPlaylist.vue index 4ec5cb64..4008e53a 100644 --- a/web-src/src/components/ModalDialogPlaylist.vue +++ b/web-src/src/components/ModalDialogPlaylist.vue @@ -50,16 +50,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.playlist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Playlist appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.playlist.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.playlist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.playlist.uri) }, open_playlist: function () { diff --git a/web-src/src/components/ModalDialogTrack.vue b/web-src/src/components/ModalDialogTrack.vue index 7cd55630..3e54f155 100644 --- a/web-src/src/components/ModalDialogTrack.vue +++ b/web-src/src/components/ModalDialogTrack.vue @@ -99,16 +99,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.track.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Track appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.track.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.track.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.track.uri) }, open_album: function () { diff --git a/web-src/src/components/SpotifyModalDialogAlbum.vue b/web-src/src/components/SpotifyModalDialogAlbum.vue index 3cecf622..9eb2eb03 100644 --- a/web-src/src/components/SpotifyModalDialogAlbum.vue +++ b/web-src/src/components/SpotifyModalDialogAlbum.vue @@ -76,16 +76,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.album.uri).then( - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 3000 }) - ) + webapi.queue_add(this.album.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.album.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Album tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.album.uri) }, open_album: function () { diff --git a/web-src/src/components/SpotifyModalDialogArtist.vue b/web-src/src/components/SpotifyModalDialogArtist.vue index c038d43e..1cc8973d 100644 --- a/web-src/src/components/SpotifyModalDialogArtist.vue +++ b/web-src/src/components/SpotifyModalDialogArtist.vue @@ -54,16 +54,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.artist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Artist tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.artist.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.artist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Artist tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.artist.uri) }, open_artist: function () { diff --git a/web-src/src/components/SpotifyModalDialogPlaylist.vue b/web-src/src/components/SpotifyModalDialogPlaylist.vue index 9b19438d..db27c9e8 100644 --- a/web-src/src/components/SpotifyModalDialogPlaylist.vue +++ b/web-src/src/components/SpotifyModalDialogPlaylist.vue @@ -58,16 +58,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.playlist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Playlist appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.playlist.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.playlist.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Playlist tracks appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.playlist.uri) }, open_playlist: function () { diff --git a/web-src/src/components/SpotifyModalDialogTrack.vue b/web-src/src/components/SpotifyModalDialogTrack.vue index efaacad6..55523a32 100644 --- a/web-src/src/components/SpotifyModalDialogTrack.vue +++ b/web-src/src/components/SpotifyModalDialogTrack.vue @@ -73,16 +73,12 @@ export default { queue_add: function () { this.$emit('close') - webapi.queue_add(this.track.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Track appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add(this.track.uri) }, queue_add_next: function () { this.$emit('close') - webapi.queue_add_next(this.track.uri).then(() => - this.$store.dispatch('add_notification', { text: 'Track appended to queue', type: 'info', timeout: 2000 }) - ) + webapi.queue_add_next(this.track.uri) }, open_album: function () { diff --git a/web-src/src/webapi/index.js b/web-src/src/webapi/index.js index ff70a6bd..c84b0bf5 100644 --- a/web-src/src/webapi/index.js +++ b/web-src/src/webapi/index.js @@ -41,8 +41,13 @@ export default { return axios.put('/api/queue/items/' + itemId + '?new_position=' + newPosition) }, - queue_add (uri) { - return axios.post('/api/queue/items/add?uris=' + uri) + queue_add (uri, showNotification = true) { + return axios.post('/api/queue/items/add?uris=' + uri).then((response) => { + if (showNotification) { + store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) + } + return Promise.resolve(response) + }) }, queue_add_next (uri) { @@ -50,7 +55,10 @@ export default { if (store.getters.now_playing && store.getters.now_playing.id) { position = store.getters.now_playing.position + 1 } - return axios.post('/api/queue/items/add?uris=' + uri + '&position=' + position) + return axios.post('/api/queue/items/add?uris=' + uri + '&position=' + position).then((response) => { + store.dispatch('add_notification', { text: response.data.count + ' tracks appended to queue', type: 'info', timeout: 2000 }) + return Promise.resolve(response) + }) }, player_status () { @@ -60,7 +68,7 @@ export default { player_play_uri (uris, shuffle, position = undefined) { return this.queue_clear().then(() => this.player_shuffle(shuffle).then(() => - this.queue_add(uris).then(() => + this.queue_add(uris, false).then(() => this.player_play({ 'position': position }) ) )