-
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.
feat: use the new single-tweet component to fetch and display a singl…
…e tweet
- Loading branch information
1 parent
a72a9f0
commit 88f5cee
Showing
4 changed files
with
33 additions
and
8 deletions.
There are no files selected for viewing
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1 @@ | ||
<p> | ||
single-tweet works! | ||
</p> | ||
<app-tweet [tweet]="tweet" [loading]="loading"></app-tweet> |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,41 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { ActivatedRoute, Params } from '@angular/router'; | ||
import { Component, OnDestroy, OnInit } from '@angular/core'; | ||
import { Subscription } from 'rxjs/Subscription'; | ||
|
||
import { TwitterService } from '../twitter.service'; | ||
|
||
@Component({ | ||
selector: 'app-single-tweet', | ||
templateUrl: './single-tweet.component.html', | ||
styleUrls: ['./single-tweet.component.css'] | ||
}) | ||
export class SingleTweetComponent implements OnInit { | ||
export class SingleTweetComponent implements OnInit, OnDestroy { | ||
private paramsSubscription: Subscription; | ||
private loading: boolean = false; | ||
private tweet: Tweet; | ||
|
||
constructor() { } | ||
constructor( | ||
private route: ActivatedRoute, | ||
private service: TwitterService, | ||
) {} | ||
|
||
ngOnInit() { | ||
this.paramsSubscription = this.route.params.subscribe(({ id }) => this.loadTweet(id)); | ||
} | ||
|
||
ngOnDestroy() { | ||
this.paramsSubscription.unsubscribe(); | ||
} | ||
|
||
private loadTweet(id: string): void { | ||
this.loading = true; | ||
|
||
this.service | ||
.getTweet(id) | ||
.subscribe( | ||
tweet => this.tweet = tweet, | ||
() => {}, | ||
() => this.loading = false, | ||
); | ||
} | ||
} |