Fix card update after edit

This commit is contained in:
Daniel Ponte 2025-01-05 16:23:30 -05:00
parent 38f68a39c3
commit 355ecc361e
3 changed files with 49 additions and 37 deletions

View file

@ -83,7 +83,10 @@
<button class="sbButton" (click)="refresh()">
<mat-icon>refresh</mat-icon>
</button>
<button [ngClass]="{ sbButton: true, hidden: !selection.hasValue() }" [matMenuTriggerFor]="callMenu">
<button
[ngClass]="{ sbButton: true, hidden: !selection.hasValue() }"
[matMenuTriggerFor]="callMenu"
>
<mat-icon>playlist_add</mat-icon>
</button>
<mat-menu #callMenu="matMenu">

View file

@ -30,7 +30,7 @@ import { debounceTime } from 'rxjs/operators';
import { ToolbarContextService } from '../navigation/toolbar-context.service';
import { MatSelectModule } from '@angular/material/select';
import { CallPlayerComponent } from './player/call-player/call-player.component';
import {MatMenuModule} from '@angular/material/menu';
import { MatMenuModule } from '@angular/material/menu';
@Pipe({
name: 'grabDate',

View file

@ -1,7 +1,14 @@
import { Component, computed, inject, ViewChild } from '@angular/core';
import { map, take, tap } from 'rxjs/operators';
import { CommonModule } from '@angular/common';
import { BehaviorSubject, Subject, Subscription } from 'rxjs';
import {
BehaviorSubject,
forkJoin,
merge,
Subject,
Subscription,
zip,
} from 'rxjs';
import { Observable } from 'rxjs';
import {
ReactiveFormsModule,
@ -89,12 +96,22 @@ export class IncidentEditDialogComponent {
}
save() {
this.incSvc.updateIncident(this.data.incID, <IncidentRecord>{
name: this.form.controls['name'].dirty ? this.form.controls['name'].value : null,
startTime: this.form.controls['start'].dirty ? this.form.controls['start'].value : null,
endTime: this.form.controls['end'].dirty ? this.form.controls['end'].value : null,
description: this.form.controls['description'].dirty ? this.form.controls['description'].value : null,
}).subscribe({
this.incSvc
.updateIncident(this.data.incID, <IncidentRecord>{
name: this.form.controls['name'].dirty
? this.form.controls['name'].value
: null,
startTime: this.form.controls['start'].dirty
? this.form.controls['start'].value
: null,
endTime: this.form.controls['end'].dirty
? this.form.controls['end'].value
: null,
description: this.form.controls['description'].dirty
? this.form.controls['description'].value
: null,
})
.subscribe({
next: (ok) => {
this.dialogRef.close(ok);
},
@ -133,7 +150,7 @@ export class IncidentEditDialogComponent {
styleUrl: './incident.component.scss',
})
export class IncidentComponent {
incPrime = new Subject<IncidentRecord>();
incPrime = new BehaviorSubject<IncidentRecord>(<IncidentRecord>{});
inc$!: Observable<IncidentRecord>;
subscriptions: Subscription = new Subscription();
dialog = inject(MatDialog);
@ -161,16 +178,13 @@ export class IncidentComponent {
ngOnInit() {
this.incID = this.route.snapshot.paramMap.get('id')!;
this.inc$ = this.incPrime.pipe();
this.incSvc
.getIncident(this.incID)
.pipe(
this.inc$ = merge(this.incSvc.getIncident(this.incID), this.incPrime).pipe(
tap((inc) => {
if (inc.calls) {
this.callsResult.data = inc.calls;
}
}),
).subscribe(this.incPrime);
);
}
editIncident(incID: string) {
@ -181,12 +195,7 @@ export class IncidentComponent {
},
});
dialogRef.afterClosed().subscribe((res) => {
if (res !== undefined) {
console.log(res);
this.incPrime.next(res);
}
});
dialogRef.afterClosed().subscribe(this.incPrime);
}
ngOnDestroy() {