Browse Source

Fixed some issues with updating songs on admin pages

Kristian Vos 3 years ago
parent
commit
2ca83547eb

+ 5 - 5
backend/logic/actions/songs.js

@@ -58,7 +58,7 @@ CacheModule.runJob("SUB", {
 	channel: "song.newVerifiedSong",
 	cb: async songId => {
 		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
-		songModel.findOne({ songId }, (err, song) => {
+		songModel.findOne({ _id: songId }, (err, song) => {
 			WSModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.songs",
 				args: ["event:admin.verifiedSong.added", song]
@@ -81,7 +81,7 @@ CacheModule.runJob("SUB", {
 	channel: "song.updatedVerifiedSong",
 	cb: async songId => {
 		const songModel = await DBModule.runJob("GET_MODEL", { modelName: "song" });
-		songModel.findOne({ songId }, (err, song) => {
+		songModel.findOne({ _id: songId }, (err, song) => {
 			WSModule.runJob("EMIT_TO_ROOM", {
 				room: "admin.songs",
 				args: ["event:admin.verifiedSong.updated", song]
@@ -475,17 +475,17 @@ export default {
 				if (song.status === "verified") {
 					CacheModule.runJob("PUB", {
 						channel: "song.updatedVerifiedSong",
-						value: song.songId
+						value: song._id
 					});
 				} else if (song.status === "unverified") {
 					CacheModule.runJob("PUB", {
 						channel: "song.updatedUnverifiedSong",
-						value: song.songId
+						value: song._id
 					});
 				} else if (song.status === "hidden") {
 					CacheModule.runJob("PUB", {
 						channel: "song.updatedHiddenSong",
-						value: song.songId
+						value: song._id
 					});
 				}
 

+ 16 - 13
frontend/src/pages/Admin/tabs/HiddenSongs.vue

@@ -191,8 +191,7 @@ export default {
 	mixins: [ScrollAndFetchHandler],
 	data() {
 		return {
-			searchQuery: "",
-			songs: []
+			searchQuery: ""
 		};
 	},
 	computed: {
@@ -207,6 +206,9 @@ export default {
 		...mapState("modalVisibility", {
 			modals: state => state.modals.admin
 		}),
+		...mapState("admin/hiddenSongs", {
+			songs: state => state.songs
+		}),
 		...mapGetters({
 			socket: "websockets/getSocket"
 		})
@@ -219,22 +221,15 @@ export default {
 	},
 	mounted() {
 		this.socket.on("event:admin.hiddenSong.added", song => {
-			this.songs.push(song);
+			this.addSong(song);
 		});
 
 		this.socket.on("event:admin.hiddenSong.removed", songId => {
-			this.songs = this.songs.filter(song => {
-				return song._id !== songId;
-			});
+			this.removeSong(songId);
 		});
 
 		this.socket.on("event:admin.hiddenSong.updated", updatedSong => {
-			for (let i = 0; i < this.songs.length; i += 1) {
-				const song = this.songs[i];
-				if (song._id === updatedSong._id) {
-					this.$set(this.songs, i, updatedSong);
-				}
-			}
+			this.updateSong(updatedSong);
 		});
 
 		if (this.socket.readyState === 1) this.init();
@@ -262,7 +257,9 @@ export default {
 				this.position,
 				"hidden",
 				data => {
-					data.forEach(song => this.songs.push(song));
+					data.forEach(song => {
+						this.addSong(song);
+					});
 
 					this.position += 1;
 					this.isGettingSet = false;
@@ -295,6 +292,12 @@ export default {
 
 			this.socket.dispatch("apis.joinAdminRoom", "hiddenSongs", () => {});
 		},
+		...mapActions("admin/hiddenSongs", [
+			// "stopVideo",
+			"addSong",
+			"removeSong",
+			"updateSong"
+		]),
 		...mapActions("modals/editSong", ["editSong", "stopVideo"]),
 		...mapActions("modalVisibility", ["openModal"])
 	}

+ 16 - 13
frontend/src/pages/Admin/tabs/UnverifiedSongs.vue

@@ -201,8 +201,7 @@ export default {
 	mixins: [ScrollAndFetchHandler],
 	data() {
 		return {
-			searchQuery: "",
-			songs: []
+			searchQuery: ""
 		};
 	},
 	computed: {
@@ -217,6 +216,9 @@ export default {
 		...mapState("modalVisibility", {
 			modals: state => state.modals.admin
 		}),
+		...mapState("admin/unverifiedSongs", {
+			songs: state => state.songs
+		}),
 		...mapGetters({
 			socket: "websockets/getSocket"
 		})
@@ -229,22 +231,15 @@ export default {
 	},
 	mounted() {
 		this.socket.on("event:admin.unverifiedSong.added", song => {
-			this.songs.push(song);
+			this.addSong(song);
 		});
 
 		this.socket.on("event:admin.unverifiedSong.removed", songId => {
-			this.songs = this.songs.filter(song => {
-				return song._id !== songId;
-			});
+			this.removeSong(songId);
 		});
 
 		this.socket.on("event:admin.unverifiedSong.updated", updatedSong => {
-			for (let i = 0; i < this.songs.length; i += 1) {
-				const song = this.songs[i];
-				if (song._id === updatedSong._id) {
-					this.$set(this.songs, i, updatedSong);
-				}
-			}
+			this.updateSong(updatedSong);
 		});
 
 		if (this.socket.readyState === 1) this.init();
@@ -284,7 +279,9 @@ export default {
 				this.position,
 				"unverified",
 				data => {
-					data.forEach(song => this.songs.push(song));
+					data.forEach(song => {
+						this.addSong(song);
+					});
 
 					this.position += 1;
 					this.isGettingSet = false;
@@ -321,6 +318,12 @@ export default {
 				() => {}
 			);
 		},
+		...mapActions("admin/unverifiedSongs", [
+			// "stopVideo",
+			"addSong",
+			"removeSong",
+			"updateSong"
+		]),
 		...mapActions("modals/editSong", ["editSong", "stopVideo"]),
 		...mapActions("modalVisibility", ["openModal"])
 	}

+ 2 - 2
frontend/src/pages/Admin/tabs/VerifiedSongs.vue

@@ -297,7 +297,7 @@ export default {
 		...mapState("modalVisibility", {
 			modals: state => state.modals.admin
 		}),
-		...mapState("admin/songs", {
+		...mapState("admin/verifiedSongs", {
 			songs: state => state.songs
 		}),
 		...mapGetters({
@@ -414,7 +414,7 @@ export default {
 
 			this.socket.dispatch("apis.joinAdminRoom", "songs", () => {});
 		},
-		...mapActions("admin/songs", [
+		...mapActions("admin/verifiedSongs", [
 			// "stopVideo",
 			"addSong",
 			"removeSong",

+ 59 - 1
frontend/src/store/modules/admin.js

@@ -10,7 +10,65 @@ const actions = {};
 const mutations = {};
 
 const modules = {
-	songs: {
+	hiddenSongs: {
+		namespaced: true,
+		state: {
+			songs: []
+		},
+		getters: {},
+		actions: {
+			addSong: ({ commit }, song) => commit("addSong", song),
+			removeSong: ({ commit }, songId) => commit("removeSong", songId),
+			updateSong: ({ commit }, updatedSong) =>
+				commit("updateSong", updatedSong)
+		},
+		mutations: {
+			addSong(state, song) {
+				state.songs.push(song);
+			},
+			removeSong(state, songId) {
+				state.songs = state.songs.filter(song => {
+					return song._id !== songId;
+				});
+			},
+			updateSong(state, updatedSong) {
+				state.songs.forEach((song, index) => {
+					if (song._id === updatedSong._id)
+						Vue.set(state.songs, index, updatedSong);
+				});
+			}
+		}
+	},
+	unverifiedSongs: {
+		namespaced: true,
+		state: {
+			songs: []
+		},
+		getters: {},
+		actions: {
+			addSong: ({ commit }, song) => commit("addSong", song),
+			removeSong: ({ commit }, songId) => commit("removeSong", songId),
+			updateSong: ({ commit }, updatedSong) =>
+				commit("updateSong", updatedSong)
+		},
+		mutations: {
+			addSong(state, song) {
+				state.songs.push(song);
+			},
+			removeSong(state, songId) {
+				state.songs = state.songs.filter(song => {
+					return song._id !== songId;
+				});
+			},
+			updateSong(state, updatedSong) {
+				state.songs.forEach((song, index) => {
+					if (song._id === updatedSong._id)
+						Vue.set(state.songs, index, updatedSong);
+				});
+			}
+		}
+	},
+	verifiedSongs: {
 		namespaced: true,
 		state: {
 			songs: []