Browse Source

Fixed duplicate items appearing when including/excluding playlists within manage station

Owen Diffey 3 years ago
parent
commit
6ba0308ede

+ 10 - 2
frontend/src/components/modals/ManageStation/index.vue

@@ -349,7 +349,11 @@ export default {
 					"event:station.includedPlaylist",
 					res => {
 						const { playlist } = res.data;
-						this.includedPlaylists.push(playlist);
+						const playlistIndex = this.includedPlaylists
+							.map(includedPlaylist => includedPlaylist._id)
+							.indexOf(playlist._id);
+						if (playlistIndex === -1)
+							this.includedPlaylists.push(playlist);
 					},
 					{ modal: "manageStation" }
 				);
@@ -358,7 +362,11 @@ export default {
 					"event:station.excludedPlaylist",
 					res => {
 						const { playlist } = res.data;
-						this.excludedPlaylists.push(playlist);
+						const playlistIndex = this.excludedPlaylists
+							.map(excludedPlaylist => excludedPlaylist._id)
+							.indexOf(playlist._id);
+						if (playlistIndex === -1)
+							this.excludedPlaylists.push(playlist);
 					},
 					{ modal: "manageStation" }
 				);

+ 8 - 2
frontend/src/pages/Station/Sidebar/Playlists.vue

@@ -141,12 +141,18 @@ export default {
 
 		this.socket.on("event:station.includedPlaylist", res => {
 			const { playlist } = res.data;
-			this.includedPlaylists.push(playlist);
+			const playlistIndex = this.includedPlaylists
+				.map(includedPlaylist => includedPlaylist._id)
+				.indexOf(playlist._id);
+			if (playlistIndex === -1) this.includedPlaylists.push(playlist);
 		});
 
 		this.socket.on("event:station.excludedPlaylist", res => {
 			const { playlist } = res.data;
-			this.excludedPlaylists.push(playlist);
+			const playlistIndex = this.excludedPlaylists
+				.map(excludedPlaylist => excludedPlaylist._id)
+				.indexOf(playlist._id);
+			if (playlistIndex === -1) this.excludedPlaylists.push(playlist);
 		});
 
 		this.socket.on("event:station.removedIncludedPlaylist", res => {