Skip to content

Commit bbbce4c

Browse files
committed
feat: This is Angular article list
1 parent 2174c8d commit bbbce4c

File tree

6 files changed

+100
-10
lines changed

6 files changed

+100
-10
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
import { ChangeDetectionStrategy, Component, Input, ViewEncapsulation } from '@angular/core';
2+
3+
import { DevCommunityRssItem } from '../dev-community-rss-parser.token';
4+
5+
const selector = '[til-article]';
6+
7+
@Component({
8+
changeDetection: ChangeDetectionStrategy.OnPush,
9+
encapsulation: ViewEncapsulation.None,
10+
selector,
11+
template: `
12+
<h2>
13+
<a [href]="rssItem?.link" target="_blank" rel="nofollow noopener">{{
14+
rssItem?.title
15+
}}</a>
16+
</h2>
17+
18+
<footer>
19+
<p>
20+
By {{ rssItem?.author }}<br />
21+
<time [dateTime]="rssItem?.isoDate">{{
22+
rssItem?.isoDate | date: 'long'
23+
}}</time
24+
><br />
25+
<span *ngFor="let tag of rssItem?.categories">#{{ tag }} </span>
26+
</p>
27+
</footer>
28+
29+
<p>{{ rssItem?.contentSnippet | tilTruncate }}</p>
30+
31+
<a [href]="rssItem?.link" target="_blank" rel="nofollow noopener"
32+
>Read article</a
33+
>
34+
`,
35+
})
36+
export class ArticleComponent {
37+
@Input()
38+
rssItem: DevCommunityRssItem | null = null;
39+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
import { CommonModule } from '@angular/common';
2+
import { NgModule } from '@angular/core';
3+
4+
import { TruncateScam } from '../truncate/truncate.scam';
5+
import { ArticleComponent } from './article.component';
6+
7+
@NgModule({
8+
declarations: [ArticleComponent],
9+
exports: [ArticleComponent],
10+
imports: [CommonModule, TruncateScam],
11+
})
12+
export class ArticleScam {}
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
1-
import {
2-
ChangeDetectionStrategy,
3-
Component,
4-
ViewEncapsulation,
5-
} from '@angular/core';
1+
import { ChangeDetectionStrategy, Component, ViewEncapsulation } from '@angular/core';
62
import { ActivatedRoute } from '@angular/router';
3+
import { Observable } from 'rxjs';
4+
import { map, tap } from 'rxjs/operators';
5+
6+
import { DevCommunityRssItems } from '../dev-community-rss-parser.token';
77

88
const selector = 'til-this-is-angular-shell';
99
@Component({
@@ -18,12 +18,27 @@ const selector = 'til-this-is-angular-shell';
1818
`,
1919
],
2020
template: `
21-
<h1>TiA shell</h1>
21+
<h1>
22+
<a [href]="rssUrl$ | async" target="_blank" rel="nofollow noopener"
23+
>This is Angular</a
24+
>
25+
</h1>
2226
23-
<h2>Route data</h2>
24-
<pre><code>{{ route.data | async | json }}</code></pre>
27+
<article
28+
til-article
29+
*ngFor="let rssItem of (rssItems$ | async) ?? []"
30+
[rssItem]="rssItem"
31+
></article>
2532
`,
2633
})
2734
export class ShellComponent {
28-
constructor(public route: ActivatedRoute) {}
35+
rssItems$: Observable<DevCommunityRssItems> = this.route.data.pipe(
36+
map((data) => data.rssItems),
37+
tap(console.log)
38+
);
39+
rssUrl$: Observable<string> = this.route.data.pipe(
40+
map((data) => data.rssUrl)
41+
);
42+
43+
constructor(private route: ActivatedRoute) {}
2944
}
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,11 @@
11
import { CommonModule } from '@angular/common';
22
import { NgModule } from '@angular/core';
33

4+
import { ArticleScam } from '../article/article.scam';
45
import { ShellComponent } from './shell.component';
56

67
@NgModule({
78
declarations: [ShellComponent],
8-
imports: [CommonModule],
9+
imports: [CommonModule, ArticleScam],
910
})
1011
export class ShellScam {}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
import { Pipe, PipeTransform } from '@angular/core';
2+
3+
@Pipe({
4+
name: 'tilTruncate',
5+
})
6+
export class TruncatePipe implements PipeTransform {
7+
transform(text: string | null | undefined): string {
8+
text ??= '';
9+
10+
const cutoff = 900;
11+
12+
return text.length <= cutoff ? text : text.substring(0, cutoff) + ' (...)';
13+
}
14+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
import { NgModule } from '@angular/core';
2+
3+
import { TruncatePipe } from './truncate.pipe';
4+
5+
@NgModule({
6+
declarations: [TruncatePipe],
7+
exports: [TruncatePipe],
8+
})
9+
export class TruncateScam {}

0 commit comments

Comments
 (0)