Skip to content

Commit d38c80f

Browse files
minor inconsistencies and improvements
1 parent 7c1a929 commit d38c80f

File tree

6 files changed

+86
-84
lines changed

6 files changed

+86
-84
lines changed

src/app/components/header/header.component.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,6 @@ p-toolbar {
7272

7373
a {
7474
font-size: 1.1rem;
75-
;
7675
text-transform: uppercase;
7776
}
7877
}

src/app/components/header/header.component.ts

Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,8 +2,8 @@ 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";
5-
import { AsyncPipe, KeyValuePipe } from "@angular/common";
6-
import { ActivatedRoute, NavigationEnd, Router, RouterLink } from "@angular/router";
5+
import { KeyValuePipe } from "@angular/common";
6+
import { ActivatedRoute, Router, RouterLink } from "@angular/router";
77
import { BlogInfo, BlogLinks } from "../../models/blog-info";
88
import { SeriesList } from "../../models/post";
99
import { SearchDialogComponent } from "../../partials/search-dialog/search-dialog.component";
@@ -20,7 +20,6 @@ import { FollowDialogComponent } from "../../partials/follow-dialog/follow-dialo
2020
selector: "app-header",
2121
standalone: true,
2222
imports: [
23-
AsyncPipe,
2423
SearchDialogComponent,
2524
SettingsDialogComponent,
2625
FollowDialogComponent,
@@ -46,8 +45,6 @@ export class HeaderComponent implements OnInit, OnDestroy {
4645
selectedTheme: string = "dark";
4746
seriesList!: SeriesList[];
4847
visible: boolean = false;
49-
private route = inject(ActivatedRoute);
50-
private router = inject(Router);
5148
themeService: ThemeService = inject(ThemeService);
5249
blogService: BlogService = inject(BlogService);
5350

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

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { Component, inject, Input, OnDestroy, OnInit } from "@angular/core";
22
import { BlogService } from "../../services/blog.service";
3-
import { AsyncPipe, DatePipe } from "@angular/common";
3+
import { AsyncPipe, DatePipe, ViewportScroller } from "@angular/common";
44
import { Post, SeriesList } from "../../models/post";
55
import { Observable, Subscription } from "rxjs";
66
import { RouterLink } from "@angular/router";
@@ -12,7 +12,6 @@ import { FooterComponent } from "../footer/footer.component";
1212
import { ThemeService } from "../../services/theme.service";
1313
import { SanitizerHtmlPipe } from "../../pipes/sanitizer-html.pipe";
1414
import { YoutubeVideoEmbedDirective } from "../../directives/youtube-video-embed.directive";
15-
import { ViewportScroller } from "@angular/common";
1615

1716
import { TagModule } from "primeng/tag";
1817
import { ToolbarModule } from "primeng/toolbar";
@@ -73,7 +72,7 @@ export class PostDetailsComponent implements OnInit, OnDestroy {
7372
this.blogName = this.blogInfo.title;
7473
const { __typename, ...links } = data.links;
7574
this.blogSocialLinks = links;
76-
this.isTeam = this.blogInfo.isTeam ? true : false;
75+
this.isTeam = this.blogInfo.isTeam ?? false;
7776
});
7877
this.post$ = this.blogService.getSinglePost(this.blogURL, this.postSlug);
7978
this.querySubscription = this.blogService

src/app/partials/settings-dialog/settings-dialog.component.ts

Lines changed: 80 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -7,89 +7,96 @@ import { InputTextModule } from "primeng/inputtext";
77
import { ButtonModule } from "primeng/button";
88

99
@Component({
10-
selector: "app-settings-dialog",
11-
standalone: true,
12-
imports: [
13-
DialogModule,
14-
InputTextModule,
15-
ButtonModule,
16-
FormsModule,
17-
ReactiveFormsModule,
18-
],
19-
templateUrl: "./settings-dialog.component.html",
20-
styleUrl: "./settings-dialog.component.scss",
10+
selector: "app-settings-dialog",
11+
standalone: true,
12+
imports: [
13+
DialogModule,
14+
InputTextModule,
15+
ButtonModule,
16+
FormsModule,
17+
ReactiveFormsModule,
18+
],
19+
templateUrl: "./settings-dialog.component.html",
20+
styleUrl: "./settings-dialog.component.scss",
2121
})
2222
export class SettingsDialogComponent implements OnInit {
23-
visible = false;
24-
blogURL: string = "hashnode.anguhashblog.com";
23+
visible = false;
24+
blogURL: string = "hashnode.anguhashblog.com";
2525
newBlogInput: string = "";
26-
newBlogURL: string = "";
27-
blogURLChanged: boolean = false;
28-
noBlogFound: boolean = false;
29-
emptyInput: boolean = false;
30-
invalidInput: boolean = false;
31-
blogService: BlogService = inject(BlogService);
26+
newBlogURL: string = "";
27+
blogURLChanged: boolean = false;
28+
noBlogFound: boolean = false;
29+
emptyInput: boolean = false;
30+
invalidInput: boolean = false;
31+
blogService: BlogService = inject(BlogService);
3232

33-
ngOnInit() {
34-
this.blogURL = this.blogService.getBlogURL();
35-
if (this.blogURL === "hashnode.anguhashblog.com") {
36-
this.blogURLChanged = false;
37-
} else {
38-
this.blogURLChanged = true;
39-
}
40-
}
33+
ngOnInit() {
34+
this.blogURL = this.blogService.getBlogURL();
35+
this.blogURLChanged = this.blogURL !== "hashnode.anguhashblog.com";
36+
}
4137

42-
changeBlogURL(): void {
43-
this.noBlogFound = false;
44-
if (this.newBlogInput === "") {
45-
this.emptyInput = true;
46-
return;
47-
} else if ( this.newBlogInput !== "") {
48-
this.emptyInput = false;
38+
changeBlogURL(): void {
39+
// Reset flags
40+
this.noBlogFound = false;
41+
this.emptyInput = false;
42+
this.invalidInput = false;
4943

50-
if (this.newBlogInput.includes("https://") || this.newBlogInput.endsWith("/")) {
51-
const cleanedBlogURL = this.newBlogInput.split("https://")[1];
52-
this.newBlogURL = cleanedBlogURL.split("/")[0];
44+
// Validate input
45+
if (!this.newBlogInput.trim()) {
46+
this.emptyInput = true;
47+
return;
48+
}
5349

54-
} else {
55-
this.newBlogURL = this.newBlogInput;
56-
}
50+
// Clean and parse the blog URL
51+
this.newBlogURL = this.cleanBlogURL(this.newBlogInput);
5752

58-
this.blogService.getBlogInfo(this.newBlogURL).subscribe((blogInfo) => {
59-
if (blogInfo === null) {
60-
this.noBlogFound = true;
61-
this.blogURLChanged = false;
62-
this.newBlogInput = "";
63-
} else {
64-
this.blogService.setBlogURL(this.newBlogURL);
65-
this.blogURL = this.blogService.getBlogURL();
66-
this.blogURLChanged = true;
67-
this.visible = false;
68-
window.location.reload();
69-
}
70-
});
71-
} else if (this.blogURL === "hashnode.anguhashblog.com") {
72-
this.blogURLChanged = false;
73-
} else {
74-
this.noBlogFound = true;
75-
this.emptyInput = false;
76-
this.blogURLChanged = false;
53+
if (!this.newBlogURL) {
7754
this.invalidInput = true;
78-
this.newBlogInput = "";
79-
}
80-
}
55+
return;
56+
}
57+
58+
// Check if it's the default URL case
59+
if (this.newBlogURL === "hashnode.anguhashblog.com") {
60+
this.blogURLChanged = false;
61+
return;
62+
}
63+
64+
// Validate blog URL via the service
65+
this.blogService.getBlogInfo(this.newBlogURL).subscribe((blogInfo) => {
66+
if (blogInfo === null) {
67+
// Blog not found
68+
this.noBlogFound = true;
69+
this.blogURLChanged = false;
70+
this.newBlogInput = "";
71+
} else {
72+
// Valid blog found
73+
this.blogService.setBlogURL(this.newBlogURL);
74+
this.blogURL = this.blogService.getBlogURL();
75+
this.blogURLChanged = true;
76+
this.visible = false;
77+
window.location.reload();
78+
}
79+
});
80+
}
8181

82+
resetBlogURL(): void {
83+
this.blogService.resetBlogURL();
84+
this.blogURL = this.blogService.getBlogURL();
85+
this.emptyInput = false;
86+
this.blogURLChanged = false;
87+
this.visible = false;
88+
window.location.reload();
89+
}
8290

83-
resetBlogURL(): void {
84-
this.blogService.resetBlogURL();
85-
this.blogURL = this.blogService.getBlogURL();
86-
this.emptyInput = false;
87-
this.blogURLChanged = false;
88-
this.visible = false;
89-
window.location.reload();
90-
}
91+
showDialog() {
92+
this.visible = true;
93+
}
9194

92-
showDialog() {
93-
this.visible = true;
94-
}
95+
private cleanBlogURL(input: string): string {
96+
// Strip "https://" and trailing slashes if present
97+
if (input.includes("https://")) {
98+
input = input.split("https://")[1];
99+
}
100+
return input.endsWith("/") ? input.slice(0, -1) : input;
101+
}
95102
}

src/app/services/blog.service.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ export class BlogService {
2929
getBlogURL(): string {
3030
if (isPlatformBrowser(this.platformId)) {
3131
return (
32-
localStorage.getItem(this.localStorageKey) ||
32+
localStorage.getItem(this.localStorageKey) ??
3333
"hashnode.anguhashblog.com"
3434
);
3535
}

src/styles.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ article {
8585
.content {
8686
p {
8787
font-size: 1.1rem;
88-
line-height: 1.5rem;;
88+
line-height: 1.5rem;
8989
}
9090
pre {
9191
overflow-y: scroll;

0 commit comments

Comments
 (0)