Skip to content

Commit

Permalink
feat: use new service method to fetch tweets
Browse files Browse the repository at this point in the history
  • Loading branch information
jessepinho committed Apr 23, 2017
1 parent b56ef0f commit 64cc245
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 23 deletions.
2 changes: 1 addition & 1 deletion src/app/timeline/timeline.component.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
<app-tweet [tweet]="tweets[currentTweetIndex]"></app-tweet>
<app-tweet [tweet]="tweets[currentTweetIndex]" *ngIf="!loading"></app-tweet>

<footer>
<div>
Expand Down
16 changes: 14 additions & 2 deletions src/app/timeline/timeline.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ const MAX_DURATION_PER_TWEET = 5000;
})
export class TimelineComponent implements OnInit {
currentTweetIndex: number = -1;
loading: boolean = false;
speed: number = 0.95;
tweets: Tweet[] = this.service.getTweets();
tweets: Tweet[] = [];
version: string = 'v' + packageJSON.version;

private timeout: number;
Expand All @@ -23,7 +24,18 @@ export class TimelineComponent implements OnInit {
) {}

ngOnInit(): void {
this.nextTweet();
this.loading = true;

this.service
.getLatestTweets()
.subscribe(
tweets => {
this.tweets = tweets;
this.nextTweet();
},
() => {},
() => this.loading = false,
);
}

private nextTweet(): void {
Expand Down
6 changes: 3 additions & 3 deletions src/app/tweet/tweet.component.html
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
<div class="wrapper">
<div class="face">
<app-face [intensity]="intensity"></app-face>
<app-face [intensity]="tweet.intensity"></app-face>
</div>
<a
href="https://twitter.com/realDonaldTrump/status/{{tweet?.id_str}}"
href="https://twitter.com/realDonaldTrump/status/{{tweet.id_str}}"
target="_blank"
class="text"
>
{{tweet?.text}}
{{tweet.text}}
</a>
</div>
18 changes: 1 addition & 17 deletions src/app/tweet/tweet.component.ts
Original file line number Diff line number Diff line change
@@ -1,29 +1,13 @@
import {
Component,
Input,
OnChanges,
SimpleChanges,
} from '@angular/core';

import { intensity } from '../helpers/intensity';
import { TwitterService } from '../twitter.service';

@Component({
selector: 'app-tweet',
templateUrl: './tweet.component.html',
styleUrls: ['./tweet.component.sass']
})
export class TweetComponent implements OnChanges {
export class TweetComponent {
@Input() tweet: Tweet;
intensity: number;

constructor(
private service: TwitterService,
) {}

ngOnChanges(changes: SimpleChanges) {
if (changes.hasOwnProperty('tweet')) {
this.intensity = this.service.getTweetIntensity(this.tweet);
}
}
}

0 comments on commit 64cc245

Please sign in to comment.