瀏覽代碼

refactor: Added update events to view punishment modal

Owen Diffey 1 年之前
父節點
當前提交
bbfcc17019
共有 3 個文件被更改,包括 22 次插入2 次删除
  1. 1 0
      backend/logic/actions/apis.js
  2. 2 2
      backend/logic/punishments.js
  3. 19 0
      frontend/src/components/modals/ViewPunishment.vue

+ 1 - 0
backend/logic/actions/apis.js

@@ -134,6 +134,7 @@ export default {
 			room.startsWith("edit-user.") ||
 			room.startsWith("view-api-request.") ||
 			room.startsWith("view-youtube-video.") ||
+			room.startsWith("view-punishment.") ||
 			room === "import-album" ||
 			room === "edit-songs"
 		) {

+ 2 - 2
backend/logic/punishments.js

@@ -148,9 +148,9 @@ class _PunishmentsModule extends CoreClass {
 									this
 								).finally(() => {
 									WSModule.runJob(
-										"EMIT_TO_ROOM",
+										"EMIT_TO_ROOMS",
 										{
-											room: `admin.punishments`,
+											rooms: [`admin.punishments`, `view-punishment.${punishment.punishmentId}`],
 											args: [
 												"event:admin.punishment.updated",
 												{ data: { punishment: { ...punishment, status: "Inactive" } } }

+ 19 - 0
frontend/src/components/modals/ViewPunishment.vue

@@ -28,6 +28,19 @@ const init = () => {
 	socket.dispatch(`punishments.findOne`, punishmentId.value, res => {
 		if (res.status === "success") {
 			viewPunishment(res.data.punishment);
+
+			socket.dispatch(
+				"apis.joinRoom",
+				`view-punishment.${punishmentId.value}`
+			);
+
+			socket.on(
+				"event:admin.punishment.updated",
+				({ data }) => {
+					punishment.value = data.punishment;
+				},
+				{ modalUuid: props.modalUuid }
+			);
 		} else {
 			new Toast("Punishment with that ID not found");
 			closeCurrentModal();
@@ -55,6 +68,12 @@ onMounted(() => {
 });
 
 onBeforeUnmount(() => {
+	socket.dispatch(
+		"apis.leaveRoom",
+		`view-punishment.${punishmentId.value}`,
+		() => {}
+	);
+
 	// Delete the Pinia store that was created for this modal, after all other cleanup tasks are performed
 	viewPunishmentStore.$dispose();
 });