-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement stale data handling for employee list based on timestamp
- Loading branch information
1 parent
308e3b3
commit 0ec18dd
Showing
4 changed files
with
105 additions
and
6 deletions.
There are no files selected for viewing
51 changes: 50 additions & 1 deletion
51
src/app/reactive-state/components/employee-list/employee-list.component.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,50 @@ | ||
<p>employee-list works!</p> | ||
<!-- <mat-card> | ||
<mat-card-title-group> | ||
<mat-card-title> Candidats </mat-card-title> | ||
</mat-card-title-group> | ||
<mat-spinner *ngIf="loading$ | async"></mat-spinner> | ||
<mat-nav-list *ngIf="employees$ | async as employees"> | ||
<a | ||
*ngFor="let employee of employees" | ||
mat-list-item | ||
routerLink="employee.id.toString()" | ||
> | ||
<img | ||
[src]="employee.imageUrl" | ||
[alt]="employee.lastName" | ||
matListItemAvatar | ||
/> | ||
<p mat-list-item>{{ employee.firstName }} {{ employee.lastName }}</p> | ||
<p mat-list-item>{{ employee.job }} chez {{ employee.company }}</p> | ||
</a> | ||
</mat-nav-list> | ||
</mat-card> --> | ||
|
||
<mat-card> | ||
<mat-card-header> | ||
<mat-card-title>Candidats</mat-card-title> | ||
</mat-card-header> | ||
|
||
<mat-card-content> | ||
<mat-spinner *ngIf="loading$ | async"></mat-spinner> | ||
|
||
<mat-nav-list *ngIf="employees$ | async as employees"> | ||
<mat-list-item | ||
*ngFor="let employee of employees" | ||
[routerLink]="employee.id.toString()" | ||
> | ||
<img | ||
matListItemAvatar | ||
[src]="employee.imageUrl" | ||
[alt]="employee.lastName" | ||
/> | ||
<div matListItemTitle> | ||
{{ employee.firstName }} {{ employee.lastName }} | ||
</div> | ||
<div matListItemLine> | ||
{{ employee.job }} chez {{ employee.company }} | ||
</div> | ||
</mat-list-item> | ||
</mat-nav-list> | ||
</mat-card-content> | ||
</mat-card> |
28 changes: 26 additions & 2 deletions
28
src/app/reactive-state/components/employee-list/employee-list.component.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,21 +1,45 @@ | ||
import { ChangeDetectionStrategy, Component, OnInit } from '@angular/core'; | ||
import { Observable } from 'rxjs'; | ||
import { EmployeesService } from '../../services/employees.service'; | ||
import { Employee } from '../../models/employee.model'; | ||
import { MatCardModule } from '@angular/material/card'; | ||
import { MatProgressSpinnerModule } from '@angular/material/progress-spinner'; | ||
import { MatToolbarModule } from '@angular/material/toolbar'; | ||
import { CommonModule } from '@angular/common'; | ||
import { Router, RouterLink, RouterLinkActive } from '@angular/router'; | ||
import { MatListModule } from '@angular/material/list'; | ||
|
||
@Component({ | ||
selector: 'app-employee-list', | ||
standalone: true, | ||
imports: [], | ||
imports: [ | ||
MatCardModule, | ||
MatProgressSpinnerModule, | ||
MatToolbarModule, | ||
MatListModule, | ||
CommonModule, | ||
RouterLink, | ||
], | ||
templateUrl: './employee-list.component.html', | ||
styleUrl: './employee-list.component.scss', | ||
changeDetection: ChangeDetectionStrategy.OnPush, // Prevents lake of performance/ reduced the possibilities of change detection | ||
}) | ||
export class EmployeeListComponent implements OnInit { | ||
loading$!: Observable<boolean>; | ||
employees$!: Observable<Employee[]>; | ||
|
||
constructor(private EmployeesService: EmployeesService) {} | ||
constructor( | ||
private router: Router, | ||
private EmployeesService: EmployeesService | ||
) {} | ||
|
||
ngOnInit(): void { | ||
this.initObservables(); | ||
this.EmployeesService.getEmployeesFromServer(); | ||
} | ||
|
||
private initObservables(): void { | ||
this.loading$ = this.EmployeesService.loading$; | ||
this.employees$ = this.EmployeesService.employees$; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters