Browse Source

fix(EditSong): if EditSong opened on top of ViewReport, socket events were being duplicated

Signed-off-by: Jonathan <theflametrooper@gmail.com>
Jonathan 3 years ago
parent
commit
2ea8b3eed4

+ 9 - 6
backend/logic/actions/reports.js

@@ -16,7 +16,10 @@ CacheModule.runJob("SUB", {
 	cb: data =>
 		WSModule.runJob("EMIT_TO_ROOMS", {
 			rooms: [`edit-song.${data.songId}`, `view-report.${data.reportId}`],
-			args: ["event:admin.report.issue.toggled", { data: { issueId: data.issueId, reportId: data.reportId } }]
+			args: [
+				"event:admin.report.issue.toggled",
+				{ data: { issueId: data.issueId, reportId: data.reportId, resolved: data.resolved } }
+			]
 		})
 });
 
@@ -193,12 +196,12 @@ export default {
 								.select({ avatar: -1, name: -1, username: -1 })
 								.exec((err, user) => {
 									if (!user)
-										next(err, {
+										reports.push({
 											...report._doc,
 											createdBy: { _id: report.createdBy }
 										});
 									else
-										next(err, {
+										reports.push({
 											...report._doc,
 											createdBy: {
 												avatar: user.avatar,
@@ -306,11 +309,11 @@ export default {
 
 					return report.save(err => {
 						if (err) return next(err.message);
-						return next(null, report.song._id);
+						return next(null, issue.resolved, report.song._id);
 					});
 				}
 			],
-			async (err, songId) => {
+			async (err, resolved, songId) => {
 				if (err) {
 					err = await UtilsModule.runJob("GET_ERROR", { error: err }, this);
 					this.log(
@@ -323,7 +326,7 @@ export default {
 
 				CacheModule.runJob("PUB", {
 					channel: "report.issue.toggle",
-					value: { reportId, issueId, songId }
+					value: { reportId, issueId, songId, resolved }
 				});
 
 				this.log(

+ 1 - 2
frontend/src/components/modals/EditSong/Tabs/Reports.vue

@@ -250,14 +250,13 @@ export default {
 		this.socket.on(
 			"event:admin.report.issue.toggled",
 			res => {
-				console.log("being toggled twice?");
 				this.reports.forEach((report, index) => {
 					if (report._id === res.data.reportId) {
 						const issue = this.reports[index].issues.find(
 							issue => issue._id.toString() === res.data.issueId
 						);
 
-						issue.resolved = !issue.resolved;
+						issue.resolved = res.data.resolved;
 					}
 				});
 			},

+ 1 - 1
frontend/src/components/modals/ViewReport.vue

@@ -150,7 +150,7 @@ export default {
 						issue => issue._id.toString() === res.data.issueId
 					);
 
-					issue.resolved = !issue.resolved;
+					issue.resolved = res.data.resolved;
 				}
 			},
 			{ modal: "viewReport" }