New Angular based web version #1
@@ -25,6 +25,7 @@ import {
|
|||||||
throwError
|
throwError
|
||||||
} from 'rxjs';
|
} from 'rxjs';
|
||||||
import { CarCardComponent } from './components/car-card/car-card.component';
|
import { CarCardComponent } from './components/car-card/car-card.component';
|
||||||
|
import { SelectedCarService } from '@vegasco-web/modules/entries/services/selected-car.service';
|
||||||
|
|
||||||
@Component({
|
@Component({
|
||||||
selector: 'app-entries',
|
selector: 'app-entries',
|
||||||
@@ -52,6 +53,7 @@ import { CarCardComponent } from './components/car-card/car-card.component';
|
|||||||
export class CarsComponent {
|
export class CarsComponent {
|
||||||
private readonly carClient = inject(CarClient);
|
private readonly carClient = inject(CarClient);
|
||||||
private readonly messageService = inject(MessageService);
|
private readonly messageService = inject(MessageService);
|
||||||
|
private readonly selectedCarService = inject(SelectedCarService);
|
||||||
|
|
||||||
protected readonly nonDeletedCars$: Observable<Car[]>;
|
protected readonly nonDeletedCars$: Observable<Car[]>;
|
||||||
|
|
||||||
@@ -78,13 +80,21 @@ export class CarsComponent {
|
|||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
onCarDeleted(entry: Car): void {
|
onCarDeleted(car: Car): void {
|
||||||
this.deletedCars$.next([...this.deletedCars$.value, entry.id]);
|
this.deletedCars$.next([...this.deletedCars$.value, car.id]);
|
||||||
this.messageService.add({
|
this.messageService.add({
|
||||||
severity: 'success',
|
severity: 'success',
|
||||||
summary: 'Auto gelöscht',
|
summary: 'Auto gelöscht',
|
||||||
detail: 'Das Auto wurde erfolgreich gelöscht.',
|
detail: 'Das Auto wurde erfolgreich gelöscht.',
|
||||||
});
|
});
|
||||||
|
this.resetSelectedCarIfDeleted(car);
|
||||||
|
}
|
||||||
|
|
||||||
|
private resetSelectedCarIfDeleted(car: Car) {
|
||||||
|
const selectedCarId = this.selectedCarService.getSelectedCarId();
|
||||||
|
if (selectedCarId === car.id) {
|
||||||
|
this.selectedCarService.setSelectedCarId(null);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
private handleGetCarsError(error: unknown): Observable<never> {
|
private handleGetCarsError(error: unknown): Observable<never> {
|
||||||
|
|||||||
Reference in New Issue
Block a user