Skip to content

Commit 498a52c

Browse files
feature(settings-dialog): input validations and error handling
feature(settings-dialog): input validations and error handling
2 parents 93a039a + 57fd666 commit 498a52c

File tree

6 files changed

+96
-28
lines changed

6 files changed

+96
-28
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.posts-view {
2-
width: 70vw;
2+
width: 80vw;
33
min-height: 67.2vh;
44
padding: 0.5rem 0;
55

@@ -12,6 +12,10 @@
1212
.post-card {
1313
display: flex;
1414
}
15+
16+
.card-title {
17+
min-height: 3.5rem;
18+
}
1519
}
1620

1721
.load-more-posts {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
.series-view {
2-
width: 70vw;
2+
width: 80vw;
33
min-height: 67.2vh;
44
padding: 0.5rem 0;
55

angular-primeng-app/src/app/partials/settings-dialog/settings-dialog.component.html

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,10 +4,10 @@
44
<p-dialog [(visible)]="visible" [style]="{width: '27vw'}">
55
@if (blogURLChanged) {
66
<div class="dialog-content">
7-
<p>Blog URL changed and set in local storage</p>
8-
<p>Reload the page to see your content loading</p>
9-
<p>When resetting you may need to click on</p>
10-
<p>the logo image to load the content again</p>
7+
<p>Blog URL was changed</p>
8+
<p>You are seeing blog posts</p>
9+
<p>from the following blog:</p>
10+
<h3>{{blogURL}}</h3>
1111
<div class="dialog-actions">
1212
<p-button label="Reset" (click)="resetBlogURL()" class="p-button-secondary"></p-button>
1313
</div>
@@ -18,15 +18,26 @@ <h3>Try with your Blog</h3>
1818
<p>try AnguHashBlog</p>
1919
<small>with another Hashnode blog </small>
2020
<span class="p-input-icon-right">
21-
@if (newBlogURL) {
22-
<i class="pi pi-times" (click)="newBlogURL=''"></i>
21+
@if (newBlogInput) {
22+
<i class="pi pi-times" (click)="newBlogInput=''"></i>
2323
}
24-
<input type="text" pInputText placeholder="Type a Blog URL" [(ngModel)]="newBlogURL" />
24+
<input type="text" pInputText placeholder="Type a Blog URL" [(ngModel)]="newBlogInput" />
25+
<div class="error">
26+
@if (emptyInput) {
27+
<small>Please provide a valid Hashnode Blog URL.</small>
28+
}
29+
@if (noBlogFound) {
30+
<small>No Hashnode Blog found.</small>
31+
}
32+
@if (invalidInput) {
33+
<small>Invalid input, please try again.</small>
34+
}
35+
</div>
2536
</span>
2637
</div>
2738
<div class="dialog-actions">
2839
<div class="dialog-actions">
29-
<p-button label="Change" (click)="changeBlogURL(); newBlogURL=''" class="p-button-secondary"></p-button>
40+
<p-button label="Change" (click)="changeBlogURL(); newBlogInput=''" class="p-button-secondary"></p-button>
3041
</div>
3142
</div>
3243
}

angular-primeng-app/src/app/partials/settings-dialog/settings-dialog.component.scss

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ p-dialog {
1515
}
1616

1717
p-button {
18-
margin: 0.5rem 0;
18+
margin: 1.5rem 0;
1919
}
2020

2121
p {
@@ -31,7 +31,16 @@ p-dialog {
3131
input {
3232
margin : 1rem 0;
3333
}
34-
}
3534

35+
36+
.error {
37+
color: red;
38+
position: absolute;
39+
top: 4rem;
40+
font-size: 0.9rem;
41+
text-align: center;
42+
font-weight: 300;
43+
}
44+
}
3645
}
3746

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

Lines changed: 51 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,12 @@ import { ButtonModule } from "primeng/button";
2222
export class SettingsDialogComponent implements OnInit {
2323
visible = false;
2424
blogURL: string = "hashnode.anguhashblog.com";
25+
newBlogInput: string = "";
2526
newBlogURL: string = "";
2627
blogURLChanged: boolean = false;
28+
noBlogFound: boolean = false;
29+
emptyInput: boolean = false;
30+
invalidInput: boolean = false;
2731
blogService: BlogService = inject(BlogService);
2832

2933
ngOnInit() {
@@ -35,21 +39,55 @@ export class SettingsDialogComponent implements OnInit {
3539
}
3640
}
3741

38-
changeBlogURL(): void {
39-
this.blogService.setBlogURL(this.newBlogURL);
40-
this.blogURL = this.blogService.getBlogURL();
41-
if (this.blogURL === "hashnode.anguhashblog.com") {
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;
49+
50+
if (this.newBlogInput.includes("https://") || this.newBlogInput.endsWith("/")) {
51+
const cleanedBlogURL = this.newBlogInput.split("https://")[1];
52+
this.newBlogURL = cleanedBlogURL.split("/")[0];
53+
54+
} else {
55+
this.newBlogURL = this.newBlogInput;
56+
}
57+
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") {
4272
this.blogURLChanged = false;
4373
} else {
44-
this.blogURLChanged = true;
45-
}
46-
}
47-
48-
resetBlogURL(): void {
49-
this.blogService.resetBlogURL();
50-
this.blogURL = this.blogService.getBlogURL();
51-
this.blogURLChanged = false;
52-
}
74+
this.noBlogFound = true;
75+
this.emptyInput = false;
76+
this.blogURLChanged = false;
77+
this.invalidInput = true;
78+
this.newBlogInput = "";
79+
}
80+
}
81+
82+
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+
}
5391

5492
showDialog() {
5593
this.visible = true;

angular-primeng-app/src/styles.scss

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ a {
77
}
88

99
.post-card {
10-
width: 20vw;
10+
width: 23vw;
1111
margin: 1rem;
1212
cursor: pointer;
1313

@@ -18,12 +18,14 @@ a {
1818

1919
.p-card {
2020
height: 100%;
21+
width: 100%;
2122
}
2223

2324
.p-card-title {
24-
font-size: 1.1rem;
25+
font-size: 1rem;
2526
line-height: 1.7rem;
2627
font-weight: 500;
28+
min-height: 3.5rem;
2729
}
2830

2931
.p-card-content {
@@ -33,7 +35,7 @@ a {
3335

3436
.card-image {
3537
width: 100%;
36-
height: 10rem;
38+
height: 12rem;
3739
overflow: hidden;
3840
border-top-left-radius: 6px;
3941
border-top-right-radius: 6px;
@@ -92,6 +94,10 @@ article {
9294
}
9395
}
9496

97+
.p-card-title {
98+
min-width: 75vw;
99+
}
100+
95101
// !important statement shall only be used if there are no alternatives, like in this case for overwriting very persistent styles set by PrimeNG
96102

97103
app-follow-dialog {

0 commit comments

Comments
 (0)