This file contains hidden or 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
| @Component({ | |
| selector: 'swkb-hero-list', | |
| templateUrl: './hero-list.component.html', | |
| styleUrls: ['./hero-list.component.scss'] | |
| }) | |
| export class HeroListComponent implements OnInit { | |
| heroes$: Observable<Hero[]>; | |
| isFirst$: Observable<boolean>; | |
| isLast$: Observable<boolean>; | |
| isLoading$: Observable<boolean>; |
This file contains hidden or 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
| <swkb-hero *ngFor="let hero of heroes$ | async; trackBy: trackByUrl" | |
| [hero]="hero"></swkb-hero> | |
| <div class="loader__bg" *ngIf="isLoading$ | async"> | |
| <mat-spinner | |
| class="loader" | |
| color="accent" | |
| mode="indeterminate" | |
| [diameter]="40" | |
| [value]="25"></mat-spinner> |
This file contains hidden or 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
| export class SwapiService { | |
| private readonly baseUrl = 'https://swapi.co/api/'; | |
| constructor(private http: HttpClient) {} | |
| getHeroes(page?: number): Observable<HeroesResponse> { | |
| const options = { | |
| params: {}, | |
| }; | |
| const link = `${this.baseUrl}people/`; |
This file contains hidden or 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
| <mat-toolbar color='primary'> | |
| <span>Star Wars Knowledge Base</span> | |
| </mat-toolbar> | |
| <swkb-hero-list></swkb-hero-list> |
This file contains hidden or 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
| <swkb-hero *ngFor="let hero of heroes$ | async; trackBy: trackByUrl" | |
| [hero]="hero"></swkb-hero> | |
| <div class="loader__bg" *ngIf="isLoading$ | async"> | |
| <mat-spinner | |
| class="loader" | |
| color="accent" | |
| mode="indeterminate" | |
| [diameter]="40" | |
| [value]="25"></mat-spinner> |
This file contains hidden or 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
| StoreModule.forRoot(reducers, { metaReducers }), | |
| !environment.production ? StoreDevtoolsModule.instrument() : [] |
This file contains hidden or 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
| export enum HeroesActionTypes { | |
| FetchHeroes = '[Heroes] Fetch Heroes', | |
| FetchHeroesSuccess = '[Heroes] Load Heroes Success', | |
| FetchHeroesError = '[Heroes] Load Heroes Error', | |
| ChangePage = '[Heroes] Change page' | |
| } | |
| export enum Pagination { | |
| NEXT, | |
| PREV |
This file contains hidden or 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
| export interface State { | |
| isLoading: boolean; | |
| error: HttpErrorResponse | null; | |
| data: Hero[] | null; | |
| next: string | null; | |
| previous: string | null; | |
| page: number; | |
| } |
This file contains hidden or 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
| export const initialState: State = { | |
| isLoading: false, | |
| error: null, | |
| data: [], | |
| next: null, | |
| previous: null, | |
| page: 1 | |
| }; |
This file contains hidden or 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
| export function reducer(state = initialState, action: HeroesActions): State { | |
| switch (action.type) { | |
| case HeroesActionTypes.FetchHeroes: | |
| return { | |
| ...state, | |
| isLoading: true, | |
| error: null | |
| }; |