From 303512402047cd07842f77cb090a054361c28415 Mon Sep 17 00:00:00 2001
From: "aditya.chandel" <>
Date: Mon, 30 Dec 2024 21:59:07 -0700
Subject: [PATCH] Add validations to library creator stepper
---
.../layout/app.topbar.component.html | 7 ++-
.../library-creator.component.html | 6 +--
.../library-creator.component.ts | 43 ++++++++++---------
.../assets/layout/styles/layout/_topbar.scss | 4 ++
4 files changed, 35 insertions(+), 25 deletions(-)
diff --git a/booklore-ui/src/app/book/component/layout/app.topbar.component.html b/booklore-ui/src/app/book/component/layout/app.topbar.component.html
index 7a25bc310..151a6e684 100644
--- a/booklore-ui/src/app/book/component/layout/app.topbar.component.html
+++ b/booklore-ui/src/app/book/component/layout/app.topbar.component.html
@@ -1,9 +1,12 @@
@@ -64,7 +64,7 @@
diff --git a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
index 5eff9dcd0..7837381f9 100644
--- a/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
+++ b/booklore-ui/src/app/book/component/library-creator/library-creator.component.ts
@@ -14,17 +14,19 @@ import {IconPickerComponent} from '../icon-picker/icon-picker.component';
providers: [MessageService]
})
export class LibraryCreatorComponent {
- value: string = '';
- folders: string[] = [];
- ref: DynamicDialogRef | undefined;
+
@ViewChild(IconPickerComponent) iconPicker: IconPickerComponent | undefined;
+ libraryName: string = '';
+ folders: string[] = [];
+ ref: DynamicDialogRef | undefined;
selectedIcon: string | null = null;
constructor(
private dialogService: DialogService,
private dynamicDialogRef: DynamicDialogRef,
private libraryService: LibraryService,
+ private messageService: MessageService,
private router: Router) {
}
@@ -67,9 +69,17 @@ export class LibraryCreatorComponent {
this.selectedIcon = null;
}
+ isLibraryDetailsValid(): boolean {
+ return !!this.libraryName.trim() && !!this.selectedIcon;
+ }
+
+ isDirectorySelectionValid(): boolean {
+ return this.folders.length > 0;
+ }
+
addLibrary() {
const newLibrary = {
- name: this.value,
+ name: this.libraryName,
paths: this.folders,
icon: this.selectedIcon ? this.selectedIcon.replace('pi pi-', '') : 'heart'
};
@@ -86,30 +96,23 @@ export class LibraryCreatorComponent {
this.dynamicDialogRef.close();
}
- /*validateLibraryNameAndProceed(nextCallback: any) {
- if (this.value.trim()) {
- this.libraryServiceV2.checkLibraryNameExists(this.value).subscribe(
- (response) => {
- const libraryExists = response && response.name === this.value;
- if (libraryExists) {
+ validateLibraryNameAndProceed(nextCallback: any) {
+ if (this.libraryName.trim()) {
+ this.libraryService.libraryState$.subscribe(
+ libraryState => {
+ let library = libraryState.libraries?.find(library => library.name === this.libraryName.trim());
+ if(library) {
this.messageService.add({
severity: 'error',
summary: 'Library Name Exists',
detail: 'This library name is already taken.',
});
} else {
- nextCallback.emit();
+ nextCallback();
}
- },
- (error) => {
- this.messageService.add({
- severity: 'error',
- summary: 'Error',
- detail: 'An error occurred while checking the library name.',
- });
}
- );
+ )
}
- }*/
+ }
}
diff --git a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
index e5f1e8402..0e8759c88 100644
--- a/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
+++ b/booklore-ui/src/assets/layout/styles/layout/_topbar.scss
@@ -334,3 +334,7 @@
transform: rotate(180deg);
transition: transform 0.3s ease-in-out;
}
+
+.half-title {
+ color: var(--primary-color);
+}