Browse Source

refactor(EditSongs): migrated EditSongs modal to new modal system

Kristian Vos 2 years ago
parent
commit
5910c8aa70

+ 2 - 1
frontend/src/components/ModalManager.vue

@@ -33,7 +33,8 @@ export default {
 			viewPunishment: "ViewPunishment.vue",
 			viewPunishment: "ViewPunishment.vue",
 			removeAccount: "RemoveAccount.vue",
 			removeAccount: "RemoveAccount.vue",
 			importAlbum: "ImportAlbum.vue",
 			importAlbum: "ImportAlbum.vue",
-			confirm: "Confirm.vue"
+			confirm: "Confirm.vue",
+			editSongs: "EditSongs.vue"
 		}),
 		}),
 		...mapState("modalVisibility", {
 		...mapState("modalVisibility", {
 			activeModals: state => state.new.activeModals,
 			activeModals: state => state.new.activeModals,

+ 11 - 6
frontend/src/components/modals/EditSongs.vue

@@ -172,6 +172,7 @@ import { mapState, mapActions, mapGetters } from "vuex";
 import { defineAsyncComponent } from "vue";
 import { defineAsyncComponent } from "vue";
 
 
 import Toast from "toasters";
 import Toast from "toasters";
+import { mapModalState, mapModalActions } from "@/vuex_helpers";
 
 
 import SongItem from "@/components/SongItem.vue";
 import SongItem from "@/components/SongItem.vue";
 
 
@@ -182,7 +183,9 @@ export default {
 		),
 		),
 		SongItem
 		SongItem
 	},
 	},
-	props: {},
+	props: {
+		modalUuid: { type: String, default: "" }
+	},
 	data() {
 	data() {
 		return {
 		return {
 			items: [],
 			items: [],
@@ -220,7 +223,7 @@ export default {
 				item => item.song._id === this.currentSong._id
 				item => item.song._id === this.currentSong._id
 			)?.flagged;
 			)?.flagged;
 		},
 		},
-		...mapState("modals/editSongs", {
+		...mapModalState("modals/editSongs/MODAL_UUID", {
 			songIds: state => state.songIds,
 			songIds: state => state.songIds,
 			songPrefillData: state => state.songPrefillData
 			songPrefillData: state => state.songPrefillData
 		}),
 		}),
@@ -269,7 +272,9 @@ export default {
 	},
 	},
 	beforeUnmount() {
 	beforeUnmount() {
 		this.socket.dispatch("apis.leaveRoom", "edit-songs");
 		this.socket.dispatch("apis.leaveRoom", "edit-songs");
-		this.resetSongs();
+		// this.resetSongs();
+		// Delete the VueX module that was created for this modal, after all other cleanup tasks are performed
+		this.$store.unregisterModule(["modals", "editSongs", this.modalUuid]);
 	},
 	},
 	methods: {
 	methods: {
 		pickSong(song) {
 		pickSong(song) {
@@ -404,11 +409,11 @@ export default {
 			else this.closeThisModal();
 			else this.closeThisModal();
 		},
 		},
 		closeThisModal() {
 		closeThisModal() {
-			this.closeModal("editSongs");
+			this.closeCurrentModal();
 		},
 		},
-		...mapActions("modalVisibility", ["openModal", "closeModal"]),
+		...mapActions("modalVisibility", ["openModal", "closeCurrentModal"]),
 		...mapActions("modals/editSong", ["editSong"]),
 		...mapActions("modals/editSong", ["editSong"]),
-		...mapActions("modals/editSongs", ["resetSongs"])
+		...mapModalActions("modals/editSongs/MODAL_UUID", ["resetSongs"])
 	}
 	}
 };
 };
 </script>
 </script>

+ 4 - 2
frontend/src/components/modals/ImportAlbum.vue

@@ -453,8 +453,10 @@ export default {
 			if (this.songsToEdit.length === 0)
 			if (this.songsToEdit.length === 0)
 				new Toast("You can't edit 0 songs.");
 				new Toast("You can't edit 0 songs.");
 			else {
 			else {
-				this.editSongs(this.songsToEdit);
-				this.openModal("editSongs");
+				this.openModal({
+					modal: "editSongs",
+					data: { songs: this.songsToEdit }
+				});
 			}
 			}
 		},
 		},
 		log(evt) {
 		log(evt) {

+ 9 - 8
frontend/src/components/modals/ImportPlaylist.vue

@@ -139,13 +139,15 @@ export default {
 						res.songs &&
 						res.songs &&
 						res.songs.length > 0
 						res.songs.length > 0
 					) {
 					) {
-						this.editSongs(
-							res.songs.map(song => ({
-								...song,
-								songId: song._id
-							}))
-						);
-						this.openModal("editSongs");
+						this.openModal({
+							modal: "editSongs",
+							data: {
+								songs: res.songs.map(song => ({
+									...song,
+									songId: song._id
+								}))
+							}
+						});
 					}
 					}
 
 
 					this.closeCurrentModal();
 					this.closeCurrentModal();
@@ -156,7 +158,6 @@ export default {
 				}
 				}
 			);
 			);
 		},
 		},
-		...mapActions("modals/editSongs", ["editSongs"]),
 		...mapActions("modalVisibility", ["openModal", "closeCurrentModal"])
 		...mapActions("modalVisibility", ["openModal", "closeCurrentModal"])
 	}
 	}
 };
 };

+ 1 - 7
frontend/src/pages/Admin/Songs.vue

@@ -257,7 +257,6 @@
 			</advanced-table>
 			</advanced-table>
 		</div>
 		</div>
 		<edit-song v-if="modals.editSong" song-type="songs" />
 		<edit-song v-if="modals.editSong" song-type="songs" />
-		<edit-songs v-if="modals.editSongs" />
 	</div>
 	</div>
 </template>
 </template>
 
 
@@ -275,9 +274,6 @@ export default {
 		EditSong: defineAsyncComponent(() =>
 		EditSong: defineAsyncComponent(() =>
 			import("@/components/modals/EditSong")
 			import("@/components/modals/EditSong")
 		),
 		),
-		EditSongs: defineAsyncComponent(() =>
-			import("@/components/modals/EditSongs.vue")
-		),
 		AdvancedTable,
 		AdvancedTable,
 		RunJobDropdown
 		RunJobDropdown
 	},
 	},
@@ -642,8 +638,7 @@ export default {
 				const songs = selectedRows.map(row => ({
 				const songs = selectedRows.map(row => ({
 					songId: row._id
 					songId: row._id
 				}));
 				}));
-				this.editSongs(songs);
-				this.openModal("editSongs");
+				this.openModal({ modal: "editSongs", data: { songs } });
 			}
 			}
 		},
 		},
 		verifyOne(songId) {
 		verifyOne(songId) {
@@ -760,7 +755,6 @@ export default {
 			}
 			}
 		},
 		},
 		...mapActions("modals/editSong", ["editSong"]),
 		...mapActions("modals/editSong", ["editSong"]),
-		...mapActions("modals/editSongs", ["editSongs"]),
 		...mapActions("modals/confirm", ["updateConfirmMessage"]),
 		...mapActions("modals/confirm", ["updateConfirmMessage"]),
 		...mapActions("modalVisibility", ["openModal"])
 		...mapActions("modalVisibility", ["openModal"])
 	}
 	}

+ 1 - 2
frontend/src/store/index.js

@@ -10,7 +10,6 @@ import station from "./modules/station";
 import admin from "./modules/admin";
 import admin from "./modules/admin";
 
 
 import editSongModal from "./modules/modals/editSong";
 import editSongModal from "./modules/modals/editSong";
-import editSongsModal from "./modules/modals/editSongs";
 
 
 const emptyModule = {
 const emptyModule = {
 	namespaced: true
 	namespaced: true
@@ -28,7 +27,7 @@ export default createStore({
 			namespaced: true,
 			namespaced: true,
 			modules: {
 			modules: {
 				editSong: editSongModal,
 				editSong: editSongModal,
-				editSongs: editSongsModal,
+				editSongs: emptyModule,
 				importAlbum: emptyModule,
 				importAlbum: emptyModule,
 				importPlaylist: emptyModule,
 				importPlaylist: emptyModule,
 				editPlaylist: emptyModule,
 				editPlaylist: emptyModule,

+ 5 - 4
frontend/src/store/modules/modalVisibility.js

@@ -14,11 +14,11 @@ import bulkActions from "./modals/bulkActions";
 import viewPunishment from "./modals/viewPunishment";
 import viewPunishment from "./modals/viewPunishment";
 import importAlbum from "./modals/importAlbum";
 import importAlbum from "./modals/importAlbum";
 import confirm from "./modals/confirm";
 import confirm from "./modals/confirm";
+import editSongs from "./modals/editSongs";
 
 
 const state = {
 const state = {
 	modals: {
 	modals: {
-		editSong: false,
-		editSongs: false
+		editSong: false
 	},
 	},
 	currentlyActive: [],
 	currentlyActive: [],
 	new: {
 	new: {
@@ -40,7 +40,8 @@ const modalModules = {
 	bulkActions,
 	bulkActions,
 	viewPunishment,
 	viewPunishment,
 	importAlbum,
 	importAlbum,
-	confirm
+	confirm,
+	editSongs
 };
 };
 
 
 const migratedModules = {
 const migratedModules = {
@@ -56,7 +57,7 @@ const migratedModules = {
 	removeAccount: true,
 	removeAccount: true,
 	editNews: true,
 	editNews: true,
 	editSong: false,
 	editSong: false,
-	editSongs: false,
+	editSongs: true,
 	editUser: true,
 	editUser: true,
 	importAlbum: true,
 	importAlbum: true,
 	viewReport: true,
 	viewReport: true,

+ 7 - 7
frontend/src/store/modules/modals/editSongs.js

@@ -8,11 +8,11 @@ export default {
 	},
 	},
 	getters: {},
 	getters: {},
 	actions: {
 	actions: {
-		editSongs: ({ commit }, songs) => commit("editSongs", songs),
-		resetSongs: ({ commit }) => commit("resetSongs")
+		init: ({ commit }, data) => commit("init", data)
+		// resetSongs: ({ commit }) => commit("resetSongs")
 	},
 	},
 	mutations: {
 	mutations: {
-		editSongs(state, songs) {
+		init(state, { songs }) {
 			state.songIds = songs.map(song => song.songId);
 			state.songIds = songs.map(song => song.songId);
 			state.songPrefillData = Object.fromEntries(
 			state.songPrefillData = Object.fromEntries(
 				songs.map(song => [
 				songs.map(song => [
@@ -20,10 +20,10 @@ export default {
 					song.prefill ? song.prefill : {}
 					song.prefill ? song.prefill : {}
 				])
 				])
 			);
 			);
-		},
-		resetSongs(state) {
-			state.songIds = [];
-			state.songPrefillData = {};
 		}
 		}
+		// resetSongs(state) {
+		// 	state.songIds = [];
+		// 	state.songPrefillData = {};
+		// }
 	}
 	}
 };
 };