#Accordion not reacting to changes

2 messages · Page 1 of 1 (latest)

rough notch
#

All-appointments

export class AllAppointmentsContainerComponent {
    private _appointmentService = inject(AppointmentService);
    public appointments$!: Observable<AppointmentModel[][]>;

    ngOnInit(): void {
      this.appointments$ = this._appointmentService.getAllAppointments();
    }
}```

```ts
@if (appointments$ | async; as appointments) {
    @if(appointments.length>0){
        <app-appointment-expansion-panel [allAppointments]="appointments"/>
    }
    @else {
        <app-appointments-not-found/>
    }
}
@else {
    <app-appointments-not-found/>
}```
#

Filter-appointments
TS

export class AppointmentFilterContainerComponent {
  private _notificationService = inject(SnackbarMessageService)
  private _appointmentService = inject(AppointmentService)

  searchedAppointments$!: Observable<AppointmentModel[][]>;
  searchForm: FormGroup;

  constructor(private fb: FormBuilder) {
    this.searchForm = this.fb.group({
      startDate: [null, Validators.required],
      endDate: [null, Validators.required],
    });
  }
  submit(): void {
    const { startDate, endDate } = this.searchForm.value;
    if (!this.checkValid(startDate, endDate)) return
    if (!this.checkOrdered(startDate, endDate)) return
    this.searchedAppointments$ = this._appointmentService.getFilteredAppointments(startDate, endDate);
  }

  checkValid(startDate:string, endDate:string): boolean {
    if(isNaN(Date.parse(startDate)) && isNaN(Date.parse(endDate))){
      this._notificationService.showMessage("A data inserida deve ser válida.");
      return false;
    }
    return true
  }

  checkOrdered(startDate:string, endDate:string): boolean {
    if(startDate > endDate){
      this._notificationService.showMessage("A data inicial deve ser menor ou igual à data final.");
      return false;
    }
    return true;
  }
}```