WIP: Match Book
This commit is contained in:
@@ -27,27 +27,30 @@
|
||||
</div>
|
||||
|
||||
<div>
|
||||
<p-button label="Search" type="submit" [disabled]="!isSearchEnabled"></p-button>
|
||||
<p-button label="Search" type="submit" [disabled]="!isSearchEnabled || loading"></p-button>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Scrollable books list -->
|
||||
<div class="mt-8 flex-1 overflow-y-auto">
|
||||
<div *ngIf="loading" class="flex justify-center items-center">
|
||||
<p-progress-spinner ariaLabel="loading" />
|
||||
</div>
|
||||
|
||||
<div *ngIf="!loading" class="mt-8 flex-1 overflow-y-auto">
|
||||
<div *ngFor="let book of books" class="flex flex-col w-full">
|
||||
<div class="flex w-full flex-row">
|
||||
<p-image [src]="book.imageUrl" alt="Image" width="110" height="100" class="mr-4"/>
|
||||
<img [src]="book.thumbnailUrl" alt="Image" class="img-fixed-dimensions pr-2" />
|
||||
<div class="flex flex-col w-full m-2">
|
||||
<div class="flex flex-row gap-4 justify-between">
|
||||
<p class="font-bold">{{ book.title }}</p>
|
||||
<p class="font-bold">{{ truncateText(book['title'], 90) }}</p>
|
||||
<div class="flex gap-4">
|
||||
<p>ISBN: {{ book.isbn }}</p>
|
||||
<p>ISBN: {{ book['isbn13'] }}</p>
|
||||
<p> | </p>
|
||||
<p>Year: {{ book.year }}</p>
|
||||
<p>Published: {{ book['publishedDate'] }}</p>
|
||||
</div>
|
||||
</div>
|
||||
<p>by {{ book.author }}</p>
|
||||
<p class="mt-4 truncate-text">
|
||||
{{ book.description }}
|
||||
<p>by {{ truncateText(book['authors'].join(', '), 70) }}</p>
|
||||
<p class="mt-4 truncate-text p-secondary">
|
||||
{{ book['description'] }}
|
||||
</p>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
@@ -5,3 +5,9 @@
|
||||
overflow: hidden;
|
||||
text-overflow: ellipsis;
|
||||
}
|
||||
|
||||
.img-fixed-dimensions {
|
||||
height: 150px;
|
||||
width: 100px;
|
||||
object-fit: fill;
|
||||
}
|
||||
|
||||
@@ -4,9 +4,14 @@ import {Button} from 'primeng/button';
|
||||
import {Select} from 'primeng/select';
|
||||
import {InputText} from 'primeng/inputtext';
|
||||
import {BookMetadataForm} from '../../book/model/book-metadata-form';
|
||||
import {Image} from 'primeng/image';
|
||||
import {Divider} from 'primeng/divider';
|
||||
import {NgForOf} from '@angular/common';
|
||||
import {NgForOf, NgIf} from '@angular/common';
|
||||
import {Provider} from '../../book/model/provider.model';
|
||||
import {BookService} from '../../book/service/book.service';
|
||||
import {FetchMetadataRequest} from '../../book/model/fetch-metadata-request.model';
|
||||
import {FetchedMetadata} from '../../book/model/book.model';
|
||||
import {DomSanitizer} from '@angular/platform-browser';
|
||||
import {ProgressSpinner} from 'primeng/progressspinner';
|
||||
|
||||
@Component({
|
||||
selector: 'app-book-match',
|
||||
@@ -17,78 +22,22 @@ import {NgForOf} from '@angular/common';
|
||||
ReactiveFormsModule,
|
||||
Button,
|
||||
InputText,
|
||||
Image,
|
||||
Divider,
|
||||
NgForOf
|
||||
NgForOf,
|
||||
NgIf,
|
||||
ProgressSpinner
|
||||
],
|
||||
standalone: true
|
||||
})
|
||||
export class BookMatchComponent implements OnChanges {
|
||||
form: FormGroup;
|
||||
providers: string[] = ['Amazon', 'Google Books', 'Google Books (API)'];
|
||||
|
||||
@Input() metadata!: BookMetadataForm;
|
||||
form: FormGroup;
|
||||
providers = Object.values(Provider);
|
||||
books: FetchedMetadata[] = [];
|
||||
loading: boolean = false;
|
||||
|
||||
books = [
|
||||
{
|
||||
title: 'Code That Fits in Your Head',
|
||||
isbn: '1234567890',
|
||||
year: 2000,
|
||||
author: 'Mark Seemann',
|
||||
description: `How to Reduce Code Complexity and Develop Software More Sustainably.
|
||||
"Mark Seemann is well known for explaining complex concepts clearly and thoroughly. In this book he condenses his wide-ranging software development experience into a set of practical, pragmatic techniques for writing sustainable and human-friendly code. This book will be a must-read for every programmer who wants to write better, more maintainable software. It covers a variety of topics from managing complexity to understanding software architecture, and helps developers see how their decisions can influence the success or failure of their projects.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/61GzazUmKyL._SL1462_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'The Pragmatic Programmer',
|
||||
isbn: '9876543210',
|
||||
year: 1999,
|
||||
author: 'Andrew Hunt',
|
||||
description: `A book that helps developers keep track of software practices and strategies that ensure long-term success. It emphasizes adaptability, flexibility, and sustainable development practices. Written by Andrew Hunt and David Thomas, this timeless classic has been guiding developers on their journey to mastering their craft for over 20 years.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/81OthjkJBuL._AC_UL320_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'Clean Code',
|
||||
isbn: '1122334455',
|
||||
year: 2008,
|
||||
author: 'Robert C. Martin',
|
||||
description: `This book provides guidelines for writing clean, maintainable code. It is divided into several sections that cover topics like meaningful naming conventions, functions, comments, and the importance of writing code that others can easily understand and work with.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/81-xuU4chcL._AC_UL320_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'Domain-Driven Design',
|
||||
isbn: '2233445566',
|
||||
year: 2003,
|
||||
author: 'Eric Evans',
|
||||
description: `In this book, Eric Evans presents a methodology for designing complex software systems called Domain-Driven Design (DDD). This approach is based on collaboration between technical experts and domain experts, working together to create a shared understanding of the problem domain and translating that into software models.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/71dx2jr5cML._AC_UL320_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'Refactoring: Improving the Design of Existing Code',
|
||||
isbn: '3344556677',
|
||||
year: 1999,
|
||||
author: 'Martin Fowler',
|
||||
description: `Refactoring provides techniques for improving the design of existing code without changing its functionality. In this book, Martin Fowler offers a practical approach to restructuring software to improve its internal structure, making it easier to understand and maintain.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/81yLrM7b4uL._AC_UL320_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'The Clean Coder',
|
||||
isbn: '4455667788',
|
||||
year: 2011,
|
||||
author: 'Robert C. Martin',
|
||||
description: `The Clean Coder focuses on what it means to be a professional software developer. Robert C. Martin (Uncle Bob) presents a series of principles and techniques that every developer should adopt to approach their work with professionalism and integrity.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/81-s6sxtdGL._AC_UL320_.jpg'
|
||||
},
|
||||
{
|
||||
title: 'Working Effectively with Legacy Code',
|
||||
isbn: '5566778899',
|
||||
year: 2004,
|
||||
author: 'Michael Feathers',
|
||||
description: `Working with legacy code can be one of the most challenging aspects of software development. Michael Feathers provides practical strategies for dealing with and improving legacy codebases that were not designed with the same care or architecture as modern software.`,
|
||||
imageUrl: 'https://m.media-amazon.com/images/I/91D4vYbkvwL._AC_UL320_.jpg'
|
||||
}
|
||||
];
|
||||
|
||||
constructor(private fb: FormBuilder) {
|
||||
constructor(private fb: FormBuilder, private bookService: BookService, private sanitizer: DomSanitizer) {
|
||||
this.form = this.fb.group({
|
||||
provider: [null],
|
||||
isbn: [''],
|
||||
@@ -116,7 +65,45 @@ export class BookMatchComponent implements OnChanges {
|
||||
|
||||
onSubmit(): void {
|
||||
if (this.form.valid) {
|
||||
console.log('Form submitted', this.form.value);
|
||||
const providerKey = Object.keys(Provider).find(
|
||||
key => Provider[key as keyof typeof Provider] === this.form.get('provider')?.value
|
||||
);
|
||||
if (!providerKey) {
|
||||
console.error('Invalid provider selected.');
|
||||
return;
|
||||
}
|
||||
const fetchRequest: FetchMetadataRequest = {
|
||||
bookId: 1,
|
||||
provider: providerKey,
|
||||
title: this.form.get('title')?.value,
|
||||
isbn: this.form.get('isbn')?.value,
|
||||
author: this.form.get('author')?.value
|
||||
};
|
||||
|
||||
this.loading = true;
|
||||
this.bookService.fetchMetadataFromSource(fetchRequest.bookId, fetchRequest)
|
||||
.subscribe({
|
||||
next: (fetchedMetadata) => {
|
||||
console.log('Metadata fetched successfully', fetchedMetadata);
|
||||
this.loading = false;
|
||||
this.books = fetchedMetadata.map((book) => ({
|
||||
...book,
|
||||
thumbnailUrl: book.thumbnailUrl
|
||||
}));
|
||||
},
|
||||
error: (err) => {
|
||||
this.loading = false;
|
||||
console.error('Error fetching metadata', err);
|
||||
}
|
||||
});
|
||||
} else {
|
||||
console.warn('Form is invalid. Please fill in all required fields.');
|
||||
}
|
||||
}
|
||||
|
||||
truncateText(text: string | null, length: number): string {
|
||||
const safeText = text ?? '';
|
||||
return safeText.length > length ? safeText.substring(0, length) + '...' : safeText;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user