Skip to content

Commit

Permalink
refactor: make the Tweet component composable
Browse files Browse the repository at this point in the history
The Timeline component now inserts a footer via ng-content. Note that this also fixes styling issues in the SingleTweet component
  • Loading branch information
jessepinho committed Apr 24, 2017
1 parent 88f5cee commit b6f128e
Show file tree
Hide file tree
Showing 6 changed files with 63 additions and 72 deletions.
24 changes: 3 additions & 21 deletions src/app/timeline/timeline.component.html
Original file line number Diff line number Diff line change
@@ -1,7 +1,5 @@
<app-tweet [tweet]="tweets[currentTweetIndex]" [loading]="loading"></app-tweet>

<footer>
<div>
<app-tweet [tweet]="tweets[currentTweetIndex]" [loading]="loading">
<div footer>
<input
type="range"
min="0"
Expand All @@ -19,20 +17,4 @@
(ngModelChange)="handleSpeedChange($event)"
>
</div>

<span class="explanation">
<span>
Louder tweets = oranger face.
</span>
<span>
By <a href="https://twitter.com/jessepinho" target="_blank">@jessepinho</a>. {{version}}

<a
href="https://github.com/jessepinho/trumpymctweetface.com"
target="_blank"
>
<img src="/assets/github.svg" alt="GitHub" class="github">
</a>
</span>
</span>
</footer>
</app-tweet>
47 changes: 0 additions & 47 deletions src/app/timeline/timeline.component.scss

This file was deleted.

4 changes: 0 additions & 4 deletions src/app/timeline/timeline.component.ts
Original file line number Diff line number Diff line change
@@ -1,21 +1,17 @@
import { Component, OnInit } from '@angular/core';

import { TwitterService } from '../twitter.service';
const packageJSON = require('../../../package.json');

const MAX_DURATION_PER_TWEET = 5000;

@Component({
selector: 'app-timeline',
templateUrl: './timeline.component.html',
styleUrls: ['./timeline.component.scss']
})
export class TimelineComponent implements OnInit {
currentTweetIndex: number = -1;
loading: boolean = false;
speed: number = 0.95;
tweets: Tweet[] = [];
version: string = 'v' + packageJSON.version;

private timeout: number;

Expand Down
20 changes: 20 additions & 0 deletions src/app/tweet/tweet.component.html
Original file line number Diff line number Diff line change
Expand Up @@ -13,3 +13,23 @@

<span class="text" *ngIf="!link">{{text}}</span>
</div>

<footer>
<ng-content select="[footer]"></ng-content>

<span class="explanation">
<span>
Louder tweets = oranger face.
</span>
<span>
By <a href="https://twitter.com/jessepinho" target="_blank">@jessepinho</a>. {{version}}

<a
href="https://github.com/jessepinho/trumpymctweetface.com"
target="_blank"
>
<img src="/assets/github.svg" alt="GitHub" class="github">
</a>
</span>
</span>
</footer>
37 changes: 37 additions & 0 deletions src/app/tweet/tweet.component.sass
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
@import url('https://fonts.googleapis.com/css?family=Gloria+Hallelujah');

\:host
display: flex
flex-direction: column

height: 100%
width: 100%

overflow: hidden

app-face
display: block
height: 100%
Expand All @@ -22,6 +31,32 @@ app-face
@media only screen and (max-aspect-ratio: 4/3)
height: initial

footer
display: flex
flex-direction: column
align-items: flex-end

flex-grow: 0
flex-shrink: 0

padding: 1rem

font-family: 'Roboto Mono', sans-serif
font-size: 0.7rem

.explanation
text-align: right

display: flex
flex-direction: column

@media only screen and (min-width: 640px)
display: initial

.github
vertical-align: middle
width: 20px

.text
box-sizing: border-box
color: black
Expand All @@ -45,6 +80,8 @@ app-face
align-items: center
display: flex
flex-direction: column
flex-grow: 1
height: 100%
width: 100%

@media only screen and (min-width: 640px)
Expand Down
3 changes: 3 additions & 0 deletions src/app/tweet/tweet.component.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ import {
Input,
} from '@angular/core';

const packageJSON = require('../../../package.json');

@Component({
selector: 'app-tweet',
templateUrl: './tweet.component.html',
Expand All @@ -15,6 +17,7 @@ export class TweetComponent {
intensity: number;
link: string;
text: string;
version: string = 'v' + packageJSON.version;

ngOnChanges(changes) {
if (changes.hasOwnProperty('loading') && this.loading) {
Expand Down

0 comments on commit b6f128e

Please sign in to comment.