Skip to content

Commit 35fb0d1

Browse files
committed
add data, ngrx state stuff, episode list stuff
1 parent f934de9 commit 35fb0d1

14 files changed

+239
-19
lines changed

package.json

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -20,27 +20,29 @@
2020
"@angular/platform-browser": "2.2.3",
2121
"@angular/platform-browser-dynamic": "2.2.3",
2222
"@angular/router": "3.2.3",
23-
"core-js": "^2.4.1",
23+
"@ngrx/core": "1.2.0",
24+
"@ngrx/store": "2.2.1",
25+
"core-js": "2.4.1",
2426
"rxjs": "5.0.0-beta.12",
25-
"ts-helpers": "^1.1.1",
26-
"zone.js": "^0.6.23"
27+
"ts-helpers": "1.1.1",
28+
"zone.js": "0.6.23"
2729
},
2830
"devDependencies": {
2931
"@angular/compiler-cli": "2.2.3",
3032
"@types/jasmine": "2.5.38",
31-
"@types/node": "^6.0.42",
33+
"@types/node": "6.0.42",
3234
"angular-cli": "1.0.0-beta.22-1",
3335
"codelyzer": "~2.0.0-beta.1",
3436
"jasmine-core": "2.5.2",
3537
"jasmine-spec-reporter": "2.5.0",
3638
"karma": "1.2.0",
37-
"karma-chrome-launcher": "^2.0.0",
38-
"karma-cli": "^1.0.1",
39-
"karma-jasmine": "^1.0.2",
40-
"karma-remap-istanbul": "^0.2.1",
39+
"karma-chrome-launcher": "2.0.0",
40+
"karma-cli": "1.0.1",
41+
"karma-jasmine": "1.0.2",
42+
"karma-remap-istanbul": "0.2.1",
4143
"protractor": "4.0.9",
4244
"ts-node": "1.2.1",
43-
"tslint": "^4.0.2",
45+
"tslint": "4.0.2",
4446
"typescript": "~2.0.3",
4547
"webdriver-manager": "10.2.5"
4648
}

src/app/app.component.html

Lines changed: 25 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,24 @@
11
<div id="logo" class="center">
22
<img src="assets/logo.png" />
33
</div>
4-
4+
<section class="center">
5+
<app-link-icon icon="twitter" link="https://twitter.com/angularair" title="Angular Air on Twitter">
6+
<div class="app-link-icon"><a href="https://twitter.com/angularair" title="Angular Air on Twitter"><i
7+
class="fa fa-twitter"></i></a></div>
8+
</app-link-icon>
9+
<app-link-icon icon="google-plus" link="https://plus.google.com/u/0/+AngularAirPodcast/posts"
10+
title="Angular Air on Google+">
11+
<div class="app-link-icon"><a href="https://plus.google.com/u/0/+AngularAirPodcast/posts"
12+
title="Angular Air on Google+"><i class="fa fa-google-plus"></i></a></div>
13+
</app-link-icon>
14+
</section>
515
<section id="title" class="center">
616
<h1>AngularAir</h1>
717
<h2>
818
A <strong>live</strong> video podcast all about Angular
919
</h2>
1020
<p>
11-
Brought to you by
12-
<a href="https://auth0.com/learn/angular-authentication/?utm_source=angular_air&utm_medium=sponsored_link&utm_campaign=target_angular">Auth0</a>,
13-
<a href="http://angularclass.com">AngularClass</a> and <a href="#sponsors">others</a>
21+
Brought to you with support from <a href="http://angularclass.com">AngularClass</a>
1422
</p>
1523
</section>
1624
<hr />
@@ -19,4 +27,16 @@ <h2>
1927
<app-subscribe-icon icon="youtube" network="YouTube" link="https://www.youtube.com/c/AngularAirPodcast"></app-subscribe-icon>
2028
<app-subscribe-icon icon="rss" network="RSS" link="http://angularair.podbean.com/feed/"></app-subscribe-icon>
2129
</section>
22-
<hr/>
30+
<hr/>
31+
<section>
32+
<h2>Featured Episode</h2>
33+
<app-episode-card [episode]="(model | async)?.featuredEpisode"></app-episode-card>
34+
</section>
35+
<section>
36+
<h2>Upcoming Episodes</h2>
37+
<app-episode-card *ngFor="let episode of (model | async)?.upcomingEpisodes" [episode]="episode"></app-episode-card>
38+
</section>
39+
<section>
40+
<h2>Past Episodes</h2>
41+
<app-episode-card *ngFor="let episode of (model | async)?.pastEpisodes" [episode]="episode"></app-episode-card>
42+
</section>

src/app/app.component.ts

Lines changed: 33 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,40 @@
1-
import { Component, ChangeDetectionStrategy } from '@angular/core';
1+
import {Component, ChangeDetectionStrategy} from '@angular/core';
2+
import {AppState, Episode} from "./shared/state/app-state";
3+
import {Store} from "@ngrx/store";
4+
import {Observable} from "rxjs";
5+
import {DateService} from "./shared/date.service";
26

37
@Component({
48
selector: 'app-root',
59
changeDetection: ChangeDetectionStrategy.OnPush,
610
templateUrl: './app.component.html',
711
styleUrls: ['./app.component.scss']
812
})
9-
export class AppComponent { }
13+
export class AppComponent {
14+
model;
15+
16+
constructor(store: Store<AppState>, dateService: DateService) {
17+
let featuredDateRange = dateService.getWeekStartAndEndDateTimeUtc();
18+
console.log(featuredDateRange);
19+
this.model = Observable.combineLatest(
20+
store.select((state: AppState) => {
21+
return state.episodes
22+
}),
23+
(episodes) => {
24+
return {
25+
featuredEpisode: episodes
26+
.find((episode: Episode) => episode.dateTimeUtc > featuredDateRange.start && episode.dateTimeUtc < featuredDateRange.end),
27+
upcomingEpisodes: episodes
28+
.filter((episode: Episode) => episode.dateTimeUtc > featuredDateRange.end)
29+
.sort((episode1: Episode, episode2: Episode) => {
30+
return episode1.dateTimeUtc - episode2.dateTimeUtc;
31+
}),
32+
pastEpisodes: episodes
33+
.filter((episode: Episode) => episode.dateTimeUtc < featuredDateRange.start)
34+
.sort((episode1: Episode, episode2: Episode) => {
35+
return episode2.dateTimeUtc - episode1.dateTimeUtc;
36+
})
37+
}
38+
});
39+
}
40+
}

src/app/app.module.ts

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,19 +6,29 @@ import { HttpModule } from '@angular/http';
66
import { AppComponent } from './app.component';
77
import { LinkIconComponent } from './shared/link-icon/link-icon.component';
88
import { SubscribeIconComponent } from './shared/subscribe-icon/subscribe-icon.component';
9+
import { DateService } from "./shared/date.service";
10+
import { StoreModule } from "@ngrx/store";
11+
import { rootReducer } from "./shared/state/root.reducer";
12+
13+
import appState from './data.json';
14+
import { EpisodeCardComponent } from './shared/episode-card/episode-card.component';
915

1016
@NgModule({
1117
declarations: [
1218
AppComponent,
1319
LinkIconComponent,
14-
SubscribeIconComponent
20+
SubscribeIconComponent,
21+
EpisodeCardComponent
1522
],
1623
imports: [
1724
BrowserModule,
1825
FormsModule,
19-
HttpModule
26+
HttpModule,
27+
StoreModule.provideStore(rootReducer, appState.data)
28+
],
29+
providers: [
30+
DateService
2031
],
21-
providers: [],
2232
bootstrap: [AppComponent]
2333
})
2434
export class AppModule { }

src/app/data.json

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,79 @@
1+
{
2+
"data": {
3+
"currentHostsIds": [4],
4+
"currentPanelistsIds": [6,7,8,9],
5+
"episodes": [
6+
{
7+
"id": 96,
8+
"title": "Discovering Angular Content",
9+
"dateTimeUtc": 1484046000000,
10+
"url": "http://ngair.io/content-2017"
11+
},
12+
{
13+
"id": 95,
14+
"title": "TIL #2",
15+
"dateTimeUtc": 1483441200000,
16+
"url": "http://ngair.io/til2-2017"
17+
},
18+
{
19+
"id": 94,
20+
"title": "Life On and Beyond the Angular Core Team",
21+
"dateTimeUtc": 1482836400000,
22+
"url": "http://ngair.io/nrwl-2016"
23+
},
24+
{
25+
"id": 93,
26+
"title": "Techniques for Testing",
27+
"dateTimeUtc": 1482231600000,
28+
"url": "http://ngair.io/testing-2016"
29+
}
30+
],
31+
"people": [
32+
{
33+
"id": 1,
34+
"fullName": "Kent C. Dodds",
35+
"twitterHandle": "kentcdodds"
36+
},
37+
{
38+
"id": 2,
39+
"fullName": "Todd Motto",
40+
"twitterHandle": "toddmotto"
41+
},
42+
{
43+
"id": 3,
44+
"fullName": "Jeff Whelpley",
45+
"twitterHandle": "jeffwhelpley"
46+
},
47+
{
48+
"id": 4,
49+
"fullName": "Justin Schwartzenberger",
50+
"twitterHandle": "schwarty"
51+
},
52+
{
53+
"id": 5,
54+
"fullName": "Patrick Stapleton",
55+
"twitterHandle": "gdi2290"
56+
},
57+
{
58+
"id": 6,
59+
"fullName": "Olivier Combe",
60+
"twitterHandle": "ocombe"
61+
},
62+
{
63+
"id": 7,
64+
"fullName": "Mike Brocchi",
65+
"twitterHandle": "brocco"
66+
},
67+
{
68+
"id": 8,
69+
"fullName": "Austin McDaniel",
70+
"twitterHandle": "amcdnl"
71+
},
72+
{
73+
"id": 9,
74+
"fullName": "Alyssa Nicoll",
75+
"twitterHandle": "AlyssaNicoll"
76+
}
77+
]
78+
}
79+
}

src/app/shared/date.service.ts

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Injectable } from '@angular/core';
2+
3+
@Injectable()
4+
export class DateService {
5+
getWeekStartAndEndDateTimeUtc() {
6+
let curr = new Date;
7+
let first = curr.getDate() - curr.getDay();
8+
let last = first + 6;
9+
return {
10+
start: curr.setDate(first),
11+
end: curr.setDate(last)
12+
};
13+
}
14+
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
<a href="{{episode.url}}">ngAir {{episode.id}} - {{episode.title}}</a>
2+
<div>{{episode.dateTimeUtc | date:'medium'}}</div>

src/app/shared/episode-card/episode-card.component.scss

Whitespace-only changes.
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import {Component, ChangeDetectionStrategy, Input} from '@angular/core';
2+
3+
@Component({
4+
selector: 'app-episode-card',
5+
templateUrl: './episode-card.component.html',
6+
styleUrls: ['./episode-card.component.scss'],
7+
changeDetection: ChangeDetectionStrategy.OnPush
8+
})
9+
export class EpisodeCardComponent {
10+
@Input() episode;
11+
}

src/app/shared/state/app-state.ts

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
export interface AppState {
2+
episodes: Episode[],
3+
people: Person[],
4+
currentHostsIds: number[],
5+
currentPanelistsIds: number[]
6+
}
7+
8+
export interface Episode {
9+
id: number,
10+
title: string,
11+
dateTimeUtc: number,
12+
url: string,
13+
hostIds: number[],
14+
guestIds: number[],
15+
panelistIds: number[]
16+
}
17+
18+
export interface Person {
19+
id: number,
20+
fullName: string,
21+
twitterHandle: string
22+
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const episodesReducer = (state, action) => {
2+
switch(action.type) {
3+
default:
4+
return state;
5+
}
6+
};
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
export const peopleReducer = (state, action) => {
2+
switch(action.type) {
3+
default:
4+
return state;
5+
}
6+
};

src/app/shared/state/root.reducer.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import {compose} from "@ngrx/core";
2+
import {combineReducers} from "@ngrx/store";
3+
import {episodesReducer} from "./episodes.reducer";
4+
import {peopleReducer} from "./people.reducer";
5+
6+
export const reducers = {
7+
episodes: episodesReducer,
8+
people: peopleReducer
9+
};
10+
11+
export function rootReducer(state, action) {
12+
return compose(combineReducers)(reducers)(state, action);
13+
}

src/typings.d.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,6 @@
11
// Typings reference file, you can add your own global typings here
22
// https://www.typescriptlang.org/docs/handbook/writing-declaration-files.html
3+
declare module "*.json" {
4+
const value: any;
5+
export default value;
6+
}

0 commit comments

Comments
 (0)