Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions src/app/app.component.ts
Original file line number Diff line number Diff line change
@@ -1,13 +1,15 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import {
combineLatest,
debounceTime,
filter,
forkJoin,
map,
Observable,
Subject,
Subscription,
switchMap,
tap,
} from 'rxjs';
import { MockDataService } from './mock-data.service';

Expand All @@ -34,7 +36,7 @@ export class AppComponent implements OnInit, OnDestroy {
// 1.1. Add functionality to changeCharactersInput method. Changes searchTermByCharacters Subject value on input change.
const inputValue: string = element.target.value;
// YOUR CODE STARTS HERE

this.searchTermByCharacters.next(inputValue)
// YOUR CODE ENDS HERE
}

Expand All @@ -48,15 +50,24 @@ export class AppComponent implements OnInit, OnDestroy {
this.charactersResults$ = this.searchTermByCharacters
.pipe
// YOUR CODE STARTS HERE

((
filter((searchedValue: string) => searchedValue.length >= 3),
debounceTime(300),
switchMap((searchedValue: string) => {
return this.mockDataService.getCharacters(searchedValue)
})
));
// YOUR CODE ENDS HERE
();

}

loadCharactersAndPlanet(): void {
// 4. On clicking the button 'Load Characters And Planets', it is necessary to process two requests and combine the results of both requests into one result array. As a result, a list with the names of the characters and the names of the planets is displayed on the screen.
// Your code should looks like this: this.planetAndCharactersResults$ = /* Your code */
// YOUR CODE STARTS HERE
this.planetAndCharactersResults$ = forkJoin(
[this.mockDataService.getCharacters(),this.mockDataService.getPlanets()]
)
// YOUR CODE ENDS HERE
}

Expand All @@ -67,12 +78,24 @@ export class AppComponent implements OnInit, OnDestroy {
- Subscribe to changes
- Check the received value using the areAllValuesTrue function and pass them to the isLoading variable. */
// YOUR CODE STARTS HERE
combineLatest([this.mockDataService.getCharactersLoader(),this.mockDataService.getPlanetLoader()])
.subscribe((res) => {
if(this.areAllValuesTrue(res) === true) {
this.isLoading = true;
}
else {
this.isLoading = false
}
})
// YOUR CODE ENDS HERE
}

ngOnDestroy(): void {
// 5.2 Unsubscribe from all subscriptions
// YOUR CODE STARTS HERE
this.subscriptions.forEach((subscription) => {
subscription?.unsubscribe
})
// YOUR CODE ENDS HERE
}

Expand Down