Skip to content

Commit 18b93da

Browse files
committed
blog host as variable
1 parent 7b833a2 commit 18b93da

File tree

10 files changed

+378
-266
lines changed

10 files changed

+378
-266
lines changed

angular-primeng-app/src/app/components/footer/footer.component.ts

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { Component } from '@angular/core';
1+
import { Component, inject } from '@angular/core';
22
import { BlogService } from '../../services/blog.service';
33
import { Subscription } from 'rxjs';
44

55
import { ToolbarModule } from 'primeng/toolbar';
6+
import { BlogInfo } from '../../models/blog-info';
67

78
@Component({
89
selector: 'app-footer',
@@ -12,17 +13,17 @@ import { ToolbarModule } from 'primeng/toolbar';
1213
styleUrl: './footer.component.scss'
1314
})
1415
export class FooterComponent {
16+
blogURL!: string;
17+
blogInfo!: BlogInfo;
1518
blogName = '';
16-
1719
date = new Date().getFullYear();
20+
blogService: BlogService = inject(BlogService);
1821

1922
private querySubscription?: Subscription;
2023

21-
constructor(private blogService: BlogService) {
22-
}
23-
2424
ngOnInit() {
25-
this.querySubscription = this.blogService.getBlogInfo()
25+
this.blogURL = this.blogService.getBlogURL();
26+
this.querySubscription = this.blogService.getBlogInfo(this.blogURL)
2627
.subscribe((data) => this.blogName = data.title);
2728
}
2829

angular-primeng-app/src/app/components/header/header.component.ts

Lines changed: 35 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,18 @@
1-
import { Component, inject, OnInit } from "@angular/core";
1+
import { Component, inject, OnDestroy, OnInit } from "@angular/core";
22
import { FormsModule } from "@angular/forms";
33
import { ThemeService } from "../../services/theme.service";
44
import { BlogService } from "../../services/blog.service";
55
import { AsyncPipe, KeyValuePipe } from "@angular/common";
66
import { RouterLink } from "@angular/router";
77
import { BlogInfo, BlogLinks } from "../../models/blog-info";
88
import { SeriesList } from "../../models/post";
9+
import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component";
10+
import { Subscription } from "rxjs";
911

1012
import { ToolbarModule } from "primeng/toolbar";
1113
import { ButtonModule } from "primeng/button";
1214
import { InputSwitchModule } from "primeng/inputswitch";
1315
import { DialogModule } from "primeng/dialog";
14-
import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component";
1516

1617
@Component({
1718
selector: "app-header",
@@ -30,10 +31,12 @@ import { SearchDialogComponent } from "../../partials/search-dialog/search-dialo
3031
templateUrl: "./header.component.html",
3132
styleUrl: "./header.component.scss",
3233
})
33-
export class HeaderComponent implements OnInit {
34-
blogInfo!: BlogInfo;
34+
export class HeaderComponent implements OnInit, OnDestroy {
35+
blogURL!: string;
36+
blogInfo!: BlogInfo;
3537
blogId: string = "";
36-
blogName: string = "";
38+
blogName: string = "";
39+
blogImage: string = "/assets/images/anguhashblog-logo-purple-bgr.jpg";
3740
blogSocialLinks!: BlogLinks;
3841
checked: boolean = true;
3942
selectedTheme: string = "dark";
@@ -42,19 +45,38 @@ export class HeaderComponent implements OnInit {
4245
themeService: ThemeService = inject(ThemeService);
4346
blogService: BlogService = inject(BlogService);
4447

48+
private querySubscription?: Subscription;
49+
4550
ngOnInit(): void {
46-
this.blogService
47-
.getBlogInfo()
51+
this.blogURL = this.blogService.getBlogURL();
52+
this.querySubscription = this.blogService
53+
.getBlogInfo(this.blogURL)
4854
.subscribe((data) => {
4955
this.blogInfo = data;
50-
this.blogId = this.blogInfo.id;
56+
this.blogId = this.blogInfo.id;
5157
this.blogName = this.blogInfo.title;
58+
if (this.blogInfo.isTeam && this.blogInfo.favicon) {
59+
this.blogImage = this.blogInfo.favicon;
60+
} else {
61+
this.blogImage = '/assets/images/anguhashblog-logo-purple-bgr.jpg'
62+
}
63+
if (!this.blogInfo.isTeam) {
64+
this.blogService
65+
.getAuthorInfo(this.blogURL)
66+
.subscribe((data) => {
67+
if (data.profilePicture) {
68+
this.blogImage = data.profilePicture;
69+
} else {
70+
this.blogImage = '/assets/images/anguhashblog-logo-purple-bgr.jpg'
71+
}
72+
});
73+
}
5274
const { __typename, ...links } = data.links;
5375
this.blogSocialLinks = links;
5476
});
5577

5678
this.blogService
57-
.getSeriesList()
79+
.getSeriesList(this.blogURL)
5880
.subscribe((data) => {
5981
this.seriesList = data;
6082
});
@@ -68,4 +90,8 @@ export class HeaderComponent implements OnInit {
6890
showDialog() {
6991
this.visible = true;
7092
}
93+
94+
ngOnDestroy(): void {
95+
this.querySubscription?.unsubscribe();
96+
}
7197
}

angular-primeng-app/src/app/components/post-details/post-details.component.ts

Lines changed: 33 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
import { Component, inject, Input, OnDestroy, OnInit } from "@angular/core";
22
import { BlogService } from "../../services/blog.service";
33
import { AsyncPipe, DatePipe } from "@angular/common";
4-
import { Post } from "../../models/post";
4+
import { Post, SeriesList } from "../../models/post";
55
import { Observable, Subscription } from "rxjs";
66
import { ActivatedRoute, RouterLink } from "@angular/router";
7-
import { BlogInfo } from "../../models/blog-info";
7+
import { BlogInfo, BlogLinks } from "../../models/blog-info";
88
import { FormsModule } from "@angular/forms";
99
import { SidenavComponent } from "../sidenav/sidenav.component";
1010
import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component";
@@ -36,28 +36,40 @@ import { DomSanitizer, SafeHtml } from "@angular/platform-browser";
3636
templateUrl: "./post-details.component.html",
3737
styleUrl: "./post-details.component.scss",
3838
})
39-
export class PostDetailsComponent implements OnInit {
40-
post$!: Observable<Post>;
41-
blogInfo!: BlogInfo;
42-
blogId: string = "";
43-
blogName: string = "";
39+
export class PostDetailsComponent implements OnInit, OnDestroy {
4440
checked: boolean = true;
4541
selectedTheme: string = "dark";
42+
blogURL!: string;
43+
blogInfo!: BlogInfo;
44+
blogId: string = "";
45+
blogName: string = "";
46+
blogSocialLinks!: BlogLinks;
47+
seriesList!: SeriesList[];
48+
post$!: Observable<Post>;
4649
themeService: ThemeService = inject(ThemeService);
4750
private sanitizer: DomSanitizer = inject(DomSanitizer);
4851
private blogService: BlogService = inject(BlogService);
52+
private querySubscription?: Subscription;
4953

50-
@Input({ required: true })
51-
set slug(slug: string) {
52-
this.post$ = this.blogService.getSinglePost(slug);
53-
}
54+
@Input({ required: true }) slug!: string;
5455

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-
});
56+
ngOnInit(): void {
57+
this.blogURL = this.blogService.getBlogURL();
58+
this.querySubscription = this.blogService
59+
.getBlogInfo(this.blogURL)
60+
.subscribe((data) => {
61+
this.blogInfo = data;
62+
this.blogId = this.blogInfo.id;
63+
this.blogName = this.blogInfo.title;
64+
const { __typename, ...links } = data.links;
65+
this.blogSocialLinks = links;
66+
});
67+
this.post$ = this.blogService.getSinglePost(this.blogURL,this.slug);
68+
this.querySubscription = this.blogService
69+
.getSeriesList(this.blogURL)
70+
.subscribe((data) => {
71+
this.seriesList = data;
72+
});
6173
}
6274

6375
sanitizeHtml(html: string): SafeHtml {
@@ -68,4 +80,8 @@ export class PostDetailsComponent implements OnInit {
6880
this.selectedTheme = theme;
6981
this.themeService.setTheme(theme);
7082
}
83+
84+
ngOnDestroy(): void {
85+
this.querySubscription?.unsubscribe();
86+
}
7187
}

angular-primeng-app/src/app/components/posts/posts.component.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,18 +9,20 @@ import { Post } from '../../models/post';
99
@Component({
1010
selector: 'app-posts',
1111
standalone: true,
12-
imports: [ AsyncPipe, CardModule],
12+
imports: [AsyncPipe, CardModule],
1313
templateUrl: './posts.component.html',
1414
styleUrl: './posts.component.scss'
1515
})
1616
export class PostsComponent implements OnInit {
17+
blogURL!: string;
1718
posts$!: Observable<Post[]>;
1819
private router = inject(Router);
1920
private blogService = inject(BlogService);
2021

21-
ngOnInit() {
22-
this.posts$ = this.blogService.getPosts();
23-
}
22+
ngOnInit() {
23+
this.blogURL = this.blogService.getBlogURL();
24+
this.posts$ = this.blogService.getPosts(this.blogURL);
25+
}
2426

2527
navigateToPost(slug: string) {
2628
this.router.navigate(['/post', slug]);

angular-primeng-app/src/app/components/series/series.component.ts

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,17 +14,19 @@ import { CardModule } from 'primeng/card';
1414
styleUrl: './series.component.scss'
1515
})
1616
export class SeriesComponent {
17+
blogURL!: string;
1718
slug: string = "";
1819
postsInSeries$!: Observable<Post[]>;
1920
blogService: BlogService = inject(BlogService);
2021
private router = inject(Router);
2122
route: ActivatedRoute = inject(ActivatedRoute);
2223

2324
ngOnInit(): void {
25+
this.blogURL = this.blogService.getBlogURL();
2426
this.postsInSeries$ = this.route.params.pipe(
2527
switchMap((params: Params) => {
2628
this.slug = params["slug"];
27-
return this.blogService.getPostsInSeries(this.slug);
29+
return this.blogService.getPostsInSeries(this.blogURL, this.slug);
2830
})
2931
);
3032
}

angular-primeng-app/src/app/components/sidenav/sidenav.component.ts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,22 +22,24 @@ import { KeyValuePipe } from '@angular/common';
2222
})
2323
export class SidenavComponent implements OnInit, OnDestroy {
2424
sidebarVisible: boolean = false;
25+
blogURL!: string;
2526
blogInfo!: BlogInfo;
2627
blogSocialLinks!: BlogLinks;
2728
seriesList!: SeriesList[];
2829
blogService: BlogService = inject(BlogService);
2930
private querySubscription?: Subscription;
3031

3132
ngOnInit(): void {
33+
this.blogURL = this.blogService.getBlogURL();
3234
this.querySubscription = this.blogService
33-
.getBlogInfo()
35+
.getBlogInfo(this.blogURL)
3436
.subscribe((data) => {
3537
this.blogInfo = data;
3638
const { __typename, ...links } = data.links;
3739
this.blogSocialLinks = links;
3840
});
3941
this.querySubscription = this.blogService
40-
.getSeriesList()
42+
.getSeriesList(this.blogURL)
4143
.subscribe((data) => {
4244
this.seriesList = data;
4345
});

0 commit comments

Comments
 (0)