@@ -22,8 +22,12 @@ import { ButtonModule } from "primeng/button";
2222export 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 ;
0 commit comments