Cleaned up code for redeemable actions.
This commit is contained in:
@ -1,4 +1,4 @@
|
||||
import { Component, EventEmitter, inject, Input, Output } from '@angular/core';
|
||||
import { Component, inject, input } from '@angular/core';
|
||||
import { MatListModule } from '@angular/material/list';
|
||||
import RedeemableAction from '../../shared/models/redeemable-action';
|
||||
import { MatButtonModule } from '@angular/material/button';
|
||||
@ -23,16 +23,14 @@ import { MatSelectModule } from '@angular/material/select';
|
||||
styleUrl: './action-list.component.scss'
|
||||
})
|
||||
export class ActionListComponent {
|
||||
@Input() actions: RedeemableAction[] = []
|
||||
@Output() actionsChange = new EventEmitter<RedeemableAction>();
|
||||
actions = input.required<RedeemableAction[]>({ alias: 'actions' });
|
||||
|
||||
readonly dialog = inject(MatDialog);
|
||||
readonly client = inject(HermesClientService);
|
||||
|
||||
opened = false;
|
||||
|
||||
create(): void {
|
||||
this.openDialog({ user_id: '', name: '', type: '', data: {} });
|
||||
this.openDialog({ user_id: '', name: '', type: '', has_message: false, data: {} });
|
||||
}
|
||||
|
||||
modify(action: RedeemableAction): void {
|
||||
@ -40,27 +38,8 @@ export class ActionListComponent {
|
||||
}
|
||||
|
||||
private openDialog(action: RedeemableAction): void {
|
||||
if (this.opened)
|
||||
return;
|
||||
|
||||
this.opened = true;
|
||||
|
||||
const dialogRef = this.dialog.open(ActionItemEditComponent, {
|
||||
data: { action: { user_id: action.user_id, name: action.name, type: action.type, data: action.data }, actions: this.actions },
|
||||
});
|
||||
|
||||
const isNewAction = action.name.length <= 0;
|
||||
dialogRef.afterClosed().subscribe((result: RedeemableAction | undefined) => {
|
||||
this.opened = false;
|
||||
if (!result)
|
||||
return;
|
||||
|
||||
if (isNewAction) {
|
||||
this.actionsChange.emit(result);
|
||||
} else {
|
||||
action.type = result.type;
|
||||
action.data = result.data;
|
||||
}
|
||||
this.dialog.open(ActionItemEditComponent, {
|
||||
data: { action: { user_id: action.user_id, name: action.name, type: action.type, data: action.data }, actions: this.actions() },
|
||||
});
|
||||
}
|
||||
}
|
||||
|
Reference in New Issue
Block a user