Initial commit

This commit is contained in:
aditya.chandel
2024-12-13 12:58:23 -07:00
commit baff376b9c
414 changed files with 552987 additions and 0 deletions
@@ -0,0 +1,21 @@
<div class="search-container" #searchContainer>
<span class="p-input-icon-left">
<i class="pi pi-search"></i>
<input
type="text"
pInputText
[(ngModel)]="searchQuery"
(input)="onSearchInputChange()"
placeholder="Search books..."
class="search-input"
#searchInput/>
<button *ngIf="searchQuery" pButton icon="pi pi-times" (click)="clearSearch()" class="clear-btn" type="button" aria-label="Clear Search"></button>
</span>
<div class="search-dropdown layout-menu" [class.show]="books.length > 0">
<div class="search-dropdown-item" *ngFor="let book of books" (click)="onBookClick(book)">
<img [src]="getBookCoverUrl(book.id)" alt="Book Cover" class="search-book-cover" />
<span class="search-book-name">{{ book.title }}</span>
</div>
</div>
</div>
@@ -0,0 +1,77 @@
.search-container {
margin-left: 20px;
position: relative; /* Ensure the dropdown is positioned relative to the container */
}
.search-dropdown {
position: absolute;
left: 0; /* Align the dropdown to the left of the container */
background-color: var(--surface-overlay); /* Use theme's background color */
border: 1px solid var(--surface-border);
border-radius: var(--border-radius);
z-index: 1000;
max-height: 300px; /* Limit the height of the dropdown */
overflow-y: auto; /* Scroll if the content exceeds max-height */
width: 600px; /* Ensures the dropdown has the same width as the search bar */
opacity: 0;
height: 0;
transition: opacity 0.3s ease, height 0.3s ease;
}
/* Show the dropdown */
.search-dropdown.show {
opacity: 1;
height: auto;
}
/* Dropdown item styles */
.search-dropdown-item {
display: flex;
align-items: center;
padding: 10px;
cursor: pointer;
transition: background-color 0.3s;
/* Hover effect */
&:hover {
background-color: var(--surface-hover);
}
}
/* Book cover styling */
.search-book-cover {
width: 25px; /* Set a fixed width */
height: 37px; /* Set a fixed height */
object-fit: cover; /* Ensure the image fits the area without distortion */
max-width: 100px; /* Max width to prevent images from becoming too big */
max-height: 150px; /* Max height to maintain consistency */
border-radius: 4px; /* Rounded corners */
margin-right: 10px; /* Space between the image and the title */
}
/* Book title styling */
.search-book-name {
font-size: 14px;
font-weight: 500;
color: var(--text-color);
flex-grow: 1; /* Allow the title to take up the remaining space */
}
/* Optionally customize the transition duration or timing */
.search-dropdown.show {
opacity: 1;
height: auto;
transition: opacity 0.3s ease, height 0.4s ease-in-out;
}
.clear-btn {
color: var(--text-color-secondary);
position: absolute;
right: 10px;
top: 50%;
transform: translateY(-50%);
background: none;
border: none;
cursor: pointer;
font-size: 12px;
}
@@ -0,0 +1,79 @@
import { Component, OnDestroy, OnInit } from '@angular/core';
import { Subject, Subscription } from 'rxjs';
import { debounceTime, distinctUntilChanged, switchMap, catchError } from 'rxjs/operators';
import { Book } from '../../model/book.model';
import { BookService } from '../../service/book.service';
import { FormsModule } from '@angular/forms';
import { InputTextModule } from 'primeng/inputtext';
import { NgForOf, NgIf } from '@angular/common';
import { ButtonDirective } from 'primeng/button';
@Component({
selector: 'app-search',
templateUrl: './search.component.html',
imports: [
FormsModule,
InputTextModule,
NgForOf,
NgIf,
ButtonDirective
],
styleUrls: ['./search.component.scss']
})
export class SearchComponent implements OnInit, OnDestroy {
searchQuery: string = '';
books: Book[] = [];
#searchSubject = new Subject<string>();
#subscription!: Subscription;
constructor(private bookService: BookService) {}
ngOnInit(): void {
this.initializeSearch();
}
initializeSearch(): void {
this.#subscription = this.#searchSubject.pipe(
debounceTime(500),
distinctUntilChanged(),
switchMap((query) => this.bookService.searchBooks(query).pipe(
catchError((error) => {
console.error('Error while searching books:', error);
return [];
})
))
).subscribe({
next: (result: Book[]) => this.books = result,
error: (error) => console.error('Subscription error:', error)
});
}
onSearchInputChange(): void {
this.#searchSubject.next(this.searchQuery.trim());
}
onBookClick(book: Book): void {
this.clearSearch();
this.openBook(book.id);
}
openBook(bookId: number): void {
const url = `/pdf-viewer/book/${bookId}`;
window.open(url, '_blank');
}
getBookCoverUrl(bookId: number): string {
return this.bookService.getBookCoverUrl(bookId);
}
clearSearch(): void {
this.searchQuery = '';
this.books = [];
}
ngOnDestroy(): void {
if (this.#subscription) {
this.#subscription.unsubscribe();
}
}
}