Skip to content

Instantly share code, notes, and snippets.

@tjoskar
Last active May 22, 2016 10:14
Show Gist options
  • Save tjoskar/9402044f45dc7d2ecbb0 to your computer and use it in GitHub Desktop.
Save tjoskar/9402044f45dc7d2ecbb0 to your computer and use it in GitHub Desktop.
Skeleton code for Chapter 3
import { Pipe } from '@angular/core';
import { Episode } from '../lib/contracts/episode';
@Pipe({
name: 'nextEpisode'
})
class NextEpisodePipe {
transform(episodes: Episode[]) {
const now = Date.now();
const nextEpisode = episodes.find(episode => {
return (new Date(episode.airdate)).getTime() > now;
});
return '';
}
generateEpisodeNumber(season, episode) {
return `S${('0' + season).slice(-2)}E${('0' + episode).slice(-2)}`;
}
}
export default NextEpisodePipe;
export {NextEpisodePipe};
import { Component, Input, Output, EventEmitter, ChangeDetectionStrategy } from '@angular/core';
import { NextEpisodePipe } from './next-episode.pipe';
@Component({
selector: 'show',
styles: [`
img {
margin: 0 10px 10px 0;
}
`],
template: `
<img [src]="show.image?.medium" [alt]="show.name" class="img-rounded" />
<div class="show-information">
<h3>Show name</h3>
<p>Next episode: </p>
<div [innerHTML]="show.summary"></div>
</div>
`,
pipes: [ NextEpisodePipe ]
})
class ShowComponent {}
export default ShowComponent;
export {ShowComponent};
import { Component, ChangeDetectionStrategy } from '@angular/core';
import { SubscribeService } from '../lib/providers';
import { ShowComponent } from './show.component';
import { Show } from '../lib/contracts/show';
@Component({
selector: 'upcoming-shows',
template: `
<h1>Upcoming shows</h1>
<!-- Render a all series here -->
`,
directives: [ ShowComponent ]
})
class UpcomingShows {
shows: Show[] = [];
constructor(service: SubscribeService) {}
}
export default UpcomingShows;
export { UpcomingShows };
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment