From 931046cbb3f105e2cdee15fa27d7ab93082805bb Mon Sep 17 00:00:00 2001 From: Tom Date: Tue, 8 Apr 2025 12:57:08 +0000 Subject: [PATCH] Cleaned up code for redeemable actions. --- .../action-item-edit.component.ts | 22 ++++--- .../action-list/action-list.component.html | 2 +- .../action-list/action-list.component.ts | 31 ++------- .../actions/actions/actions.component.html | 8 +-- src/app/actions/actions/actions.component.ts | 63 +++++-------------- .../connection-list.component.scss | 14 ++--- src/app/hermes-client.service.ts | 8 +-- src/app/keys/key-list/key-list.component.scss | 14 ++--- .../permission-list.component.scss | 14 ++--- src/app/shared/models/redeemable-action.ts | 1 + .../services/redeemable-action.service.ts | 2 +- .../twitch-user-list.component.scss | 14 ++--- 12 files changed, 72 insertions(+), 121 deletions(-) diff --git a/src/app/actions/action-item-edit/action-item-edit.component.ts b/src/app/actions/action-item-edit/action-item-edit.component.ts index fb7c9da..f4b4978 100644 --- a/src/app/actions/action-item-edit/action-item-edit.component.ts +++ b/src/app/actions/action-item-edit/action-item-edit.component.ts @@ -28,10 +28,12 @@ import { MatIconModule } from '@angular/material/icon'; }) export class ActionItemEditComponent implements OnInit { private readonly client = inject(HermesClientService); - readonly dialogRef = inject(MatDialogRef); private readonly data = inject<{ action: RedeemableAction, actions: RedeemableAction[] }>(MAT_DIALOG_DATA); + readonly dialogRef = inject(MatDialogRef); + action = this.data.action; actions = this.data.actions; + readonly actionEntries: ({ [key: string]: any[] }) = { 'SLEEP': [ { @@ -272,18 +274,18 @@ export class ActionItemEditComponent implements OnInit { return; } - this.action.name = this.formGroup.get('name')!.value!; - this.action.type = this.formGroup.get('type')!.value!; - this.action.data = {} - for (const entry of this.actionEntries[this.action.type]) { - this.action.data[entry.key] = entry.control.value!.toString(); - } - if (!(this.action.type in this.actionEntries)) { this.waitForResponse = false; return; } + this.action.name = this.formGroup.get('name')!.value!; + this.action.type = this.formGroup.get('type')!.value!; + this.action.data = {}; + for (const entry of this.actionEntries[this.action.type]) { + this.action.data[entry.key] = entry.control.value!.toString(); + } + const isNewAction = !this.action.user_id; const requestType = isNewAction ? 'create_redeemable_action' : 'update_redeemable_action'; this.client.first((d: any) => d.op == 4 && d.d.request.type == requestType && d.d.data.name == this.action.name) @@ -299,8 +301,8 @@ export class ActionItemEditComponent implements OnInit { complete: () => this.waitForResponse = false, }); if (isNewAction) - this.client.createRedeemableAction(this.action.name, this.action.type, this.action.data); + this.client.createRedeemableAction(this.action.name, this.action.type, false, this.action.data); else - this.client.updateRedeemableAction(this.action.name, this.action.type, this.action.data); + this.client.updateRedeemableAction(this.action.name, this.action.type, false, this.action.data); } } diff --git a/src/app/actions/action-list/action-list.component.html b/src/app/actions/action-list/action-list.component.html index 28b824c..a4657e4 100644 --- a/src/app/actions/action-list/action-list.component.html +++ b/src/app/actions/action-list/action-list.component.html @@ -1,5 +1,5 @@
- @for (action of actions; track action.name) { + @for (action of actions(); track action.name) {