@@ -22,8 +22,12 @@ import { ButtonModule } from "primeng/button";
22
22
export class SettingsDialogComponent implements OnInit {
23
23
visible = false ;
24
24
blogURL : string = "hashnode.anguhashblog.com" ;
25
+ newBlogInput : string = "" ;
25
26
newBlogURL : string = "" ;
26
27
blogURLChanged : boolean = false ;
28
+ noBlogFound : boolean = false ;
29
+ emptyInput : boolean = false ;
30
+ invalidInput : boolean = false ;
27
31
blogService : BlogService = inject ( BlogService ) ;
28
32
29
33
ngOnInit ( ) {
@@ -35,21 +39,55 @@ export class SettingsDialogComponent implements OnInit {
35
39
}
36
40
}
37
41
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" ) {
42
72
this . blogURLChanged = false ;
43
73
} 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
+ }
53
91
54
92
showDialog ( ) {
55
93
this . visible = true ;
0 commit comments