Browse Source

fix(Queue): cleaned up code to undo repositioning of song if backend failure

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 3 years ago
parent
commit
f4c491f335
1 changed files with 16 additions and 20 deletions
  1. 16 20
      frontend/src/components/Queue.vue

+ 16 - 20
frontend/src/components/Queue.vue

@@ -240,21 +240,12 @@ export default {
 				},
 				res => {
 					new Toast({ content: res.message, timeout: 4000 });
-					if (res.status !== "success") {
-						if (this.sector === "station") {
-							this.repositionSongInListStation({
-								...moved.element,
-								newIndex: moved.oldIndex,
-								oldIndex: moved.newIndex
-							});
-						} else if (this.sector === "manageStation") {
-							this.repositionSongInListManageStation({
-								...moved.element,
-								newIndex: moved.oldIndex,
-								oldIndex: moved.newIndex
-							});
-						}
-					}
+					if (res.status !== "success")
+						this.repositionSongInList({
+							...moved.element,
+							newIndex: moved.oldIndex,
+							oldIndex: moved.newIndex
+						});
 				}
 			);
 		},
@@ -276,11 +267,16 @@ export default {
 				}
 			});
 		},
-		...mapActions("modals/manageStation", {
-			repositionSongInListManageStation: "repositionSongInList"
-		}),
-		...mapActions("station", {
-			repositionSongInListStation: "repositionSongInList"
+		...mapActions({
+			repositionSongInList(dispatch, payload) {
+				if (this.sector === "manageStation")
+					return dispatch(
+						"modals/manageStation/repositionSongInList",
+						payload
+					);
+
+				return dispatch("station/repositionSongInList", payload);
+			}
 		}),
 		...mapActions("modalVisibility", ["openModal"]),
 		...mapActions({