Skip to content

Commit fcc86a4

Browse files
authored
FE - Article tags and display articles by tags (#19)
* FE - Article tags and display articles by tags * Add markdown for article content display
1 parent 0441583 commit fcc86a4

17 files changed

+1726
-259
lines changed

frontend/package-lock.json

Lines changed: 1626 additions & 238 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

frontend/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
"@angular/platform-browser": "^17.3.0",
1919
"@angular/platform-browser-dynamic": "^17.3.0",
2020
"@angular/router": "^17.3.0",
21+
"ngx-markdown": "~17.2.0",
2122
"rxjs": "~7.8.0",
2223
"tslib": "^2.3.0",
2324
"zone.js": "~0.14.3"

frontend/src/app/app.module.ts

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import { AppComponent } from './app.component';
66
import { LayoutModule } from "./layout/layout.module";
77
import { PagesModule } from "./pages/pages.module";
88
import { provideHttpClient } from "@angular/common/http";
9+
import { MarkdownModule } from "ngx-markdown";
910

1011
@NgModule({
1112
declarations: [
@@ -14,6 +15,7 @@ import { provideHttpClient } from "@angular/common/http";
1415
imports: [
1516
BrowserModule,
1617
AppRoutingModule,
18+
MarkdownModule.forRoot(),
1719

1820
LayoutModule,
1921
PagesModule
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export interface TagsResponse {
2+
tags: string[];
3+
}

frontend/src/app/common/models/view/feed.view-model.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,6 @@ export interface FeedMenu {
77
export enum FeedMenuEnum {
88
MINE = 'mine',
99
GLOBAL = 'global',
10-
FAVORITES = 'favorites'
10+
FAVORITES = 'favorites',
11+
TAGS = 'tags'
1112
}

frontend/src/app/common/services/api/article.service.ts

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ import {
1313
ArticleCommentsResponse,
1414
CreateArticleCommentPayload
1515
} from "../../models/api/comment.model";
16+
import { TagsResponse } from "../../models/api/tag.model";
1617

1718
@Injectable({
1819
providedIn: 'root'
@@ -66,4 +67,8 @@ export class ArticleService {
6667
public deleteArticleComment(articleSlug: string, commentId: number): Observable<void> {
6768
return this._requestHelper.delete(`/articles/${ articleSlug }/comments/${ commentId }`);
6869
}
70+
71+
public queryTags(): Observable<TagsResponse> {
72+
return this._requestHelper.get('/tags');
73+
}
6974
}
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
<p>Popular Tags</p>
2+
3+
<div class="tag-list">
4+
<a *ngFor="let tag of tags" (click)="tagSelected.emit(tag)" routerLink="" class="tag-pill tag-default">{{ tag }}</a>
5+
</div>

frontend/src/app/pages/article/article-tags/article-tags.component.scss

Whitespace-only changes.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
// import { ComponentFixture, TestBed } from '@angular/core/testing';
2+
//
3+
// import { ArticleTagsComponent } from './article-tags.component';
4+
//
5+
// describe('ArticleTagsComponent', () => {
6+
// let component: ArticleTagsComponent;
7+
// let fixture: ComponentFixture<ArticleTagsComponent>;
8+
//
9+
// beforeEach(async () => {
10+
// await TestBed.configureTestingModule({
11+
// declarations: [ArticleTagsComponent]
12+
// })
13+
// .compileComponents();
14+
//
15+
// fixture = TestBed.createComponent(ArticleTagsComponent);
16+
// component = fixture.componentInstance;
17+
// fixture.detectChanges();
18+
// });
19+
//
20+
// it('should create', () => {
21+
// expect(component).toBeTruthy();
22+
// });
23+
// });
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
import { Component, EventEmitter, Output } from '@angular/core';
2+
import { ArticleService } from "../../../common/services/api/article.service";
3+
4+
@Component({
5+
selector: 'app-article-tags',
6+
templateUrl: './article-tags.component.html',
7+
styleUrl: './article-tags.component.scss'
8+
})
9+
export class ArticleTagsComponent {
10+
@Output() tagSelected: EventEmitter<string> = new EventEmitter();
11+
12+
public tags: string[] = [];
13+
14+
constructor(
15+
private readonly _articleService: ArticleService
16+
) {
17+
this._loadTags();
18+
}
19+
20+
private _loadTags(): void {
21+
this._articleService.queryTags().subscribe(response => {
22+
this.tags = response.tags;
23+
});
24+
}
25+
}

0 commit comments

Comments
 (0)