|
1 | | -import { Component, inject, Input, OnDestroy, OnInit } from '@angular/core'; |
2 | | -import { BlogService } from '../../services/blog.service'; |
3 | | -import { AsyncPipe, DatePipe } from '@angular/common'; |
4 | | -import { Post } from '../../models/post'; |
5 | | -import { Observable, Subscription } from 'rxjs'; |
6 | | -import { ActivatedRoute, RouterLink } from '@angular/router'; |
7 | | -import { BlogInfo, BlogLinks } from '../../models/blog-info'; |
8 | | -import { FormsModule } from '@angular/forms'; |
9 | | -import { SidenavComponent } from '../sidenav/sidenav.component'; |
10 | | -import { FooterComponent } from '../footer/footer.component'; |
11 | | -import { ThemeService } from '../../services/theme.service'; |
| 1 | +import { Component, inject, Input, OnDestroy, OnInit } from "@angular/core"; |
| 2 | +import { BlogService } from "../../services/blog.service"; |
| 3 | +import { AsyncPipe, DatePipe } from "@angular/common"; |
| 4 | +import { Post } from "../../models/post"; |
| 5 | +import { Observable, Subscription } from "rxjs"; |
| 6 | +import { ActivatedRoute, RouterLink } from "@angular/router"; |
| 7 | +import { BlogInfo } from "../../models/blog-info"; |
| 8 | +import { FormsModule } from "@angular/forms"; |
| 9 | +import { SidenavComponent } from "../sidenav/sidenav.component"; |
| 10 | +import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component"; |
| 11 | +import { FooterComponent } from "../footer/footer.component"; |
| 12 | +import { ThemeService } from "../../services/theme.service"; |
12 | 13 |
|
13 | | -import { TagModule } from 'primeng/tag'; |
| 14 | +import { TagModule } from "primeng/tag"; |
14 | 15 | import { ToolbarModule } from "primeng/toolbar"; |
15 | 16 | import { ButtonModule } from "primeng/button"; |
16 | 17 | import { InputSwitchModule } from "primeng/inputswitch"; |
17 | | - |
18 | | -import { SanitizerHtmlPipe } from "../../pipes/sanitizer-html.pipe"; |
19 | | -import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component"; |
| 18 | +import { DomSanitizer, SafeHtml } from "@angular/platform-browser"; |
20 | 19 |
|
21 | 20 | @Component({ |
22 | | - selector: 'app-post-details', |
23 | | - standalone: true, |
24 | | - imports: [ |
25 | | - DatePipe, |
26 | | - AsyncPipe, |
27 | | - RouterLink, |
28 | | - SidenavComponent, |
29 | | - FooterComponent, |
30 | | - FormsModule, |
31 | | - TagModule, |
32 | | - ToolbarModule, |
33 | | - ButtonModule, |
34 | | - InputSwitchModule, |
35 | | - SanitizerHtmlPipe, |
36 | | - SearchDialogComponent |
37 | | - ], |
38 | | - templateUrl: './post-details.component.html', |
39 | | - styleUrl: './post-details.component.scss' |
| 21 | + selector: "app-post-details", |
| 22 | + standalone: true, |
| 23 | + imports: [ |
| 24 | + DatePipe, |
| 25 | + AsyncPipe, |
| 26 | + RouterLink, |
| 27 | + SidenavComponent, |
| 28 | + FooterComponent, |
| 29 | + FormsModule, |
| 30 | + TagModule, |
| 31 | + ToolbarModule, |
| 32 | + ButtonModule, |
| 33 | + InputSwitchModule, |
| 34 | + SearchDialogComponent, |
| 35 | + ], |
| 36 | + templateUrl: "./post-details.component.html", |
| 37 | + styleUrl: "./post-details.component.scss", |
40 | 38 | }) |
41 | 39 | export class PostDetailsComponent implements OnInit { |
42 | | - post$!: Observable<Post>; |
43 | | - blogInfo!: BlogInfo; |
44 | | - blogId: string = ""; |
45 | | - blogName: string = ""; |
46 | | - checked: boolean = true; |
47 | | - selectedTheme: string = "dark"; |
48 | | - themeService: ThemeService = inject(ThemeService); |
49 | | - private blogService: BlogService = inject(BlogService); |
| 40 | + post$!: Observable<Post>; |
| 41 | + blogInfo!: BlogInfo; |
| 42 | + blogId: string = ""; |
| 43 | + blogName: string = ""; |
| 44 | + checked: boolean = true; |
| 45 | + selectedTheme: string = "dark"; |
| 46 | + themeService: ThemeService = inject(ThemeService); |
| 47 | + private sanitizer: DomSanitizer = inject(DomSanitizer); |
| 48 | + private blogService: BlogService = inject(BlogService); |
| 49 | + |
| 50 | + @Input({ required: true }) |
| 51 | + set slug(slug: string) { |
| 52 | + this.post$ = this.blogService.getSinglePost(slug); |
| 53 | + } |
50 | 54 |
|
51 | | - @Input({required: true}) |
52 | | - set slug(slug: string) { |
53 | | - this.post$ = this.blogService.getSinglePost(slug); |
54 | | - } |
| 55 | + ngOnInit(): void { |
| 56 | + this.blogService.getBlogInfo().subscribe((data) => { |
| 57 | + this.blogInfo = data; |
| 58 | + this.blogId = this.blogInfo.id; |
| 59 | + this.blogName = this.blogInfo.title; |
| 60 | + }); |
| 61 | + } |
55 | 62 |
|
56 | | - ngOnInit(): void { |
57 | | - this.blogService |
58 | | - .getBlogInfo() |
59 | | - .subscribe((data) => { |
60 | | - this.blogInfo = data; |
61 | | - this.blogId = this.blogInfo.id; |
62 | | - this.blogName = this.blogInfo.title; |
63 | | - }); |
64 | | - } |
| 63 | + sanitizeHtml(html: string): SafeHtml { |
| 64 | + return this.sanitizer.bypassSecurityTrustHtml(html); |
| 65 | + } |
65 | 66 |
|
66 | | - onThemeChange(theme: string): void { |
67 | | - this.selectedTheme = theme; |
68 | | - this.themeService.setTheme(theme); |
69 | | - } |
| 67 | + onThemeChange(theme: string): void { |
| 68 | + this.selectedTheme = theme; |
| 69 | + this.themeService.setTheme(theme); |
| 70 | + } |
70 | 71 | } |
0 commit comments