|
1 | | -import { Component, input } from '@angular/core'; |
| 1 | +import { Component, computed, input } from '@angular/core'; |
| 2 | +import { environment } from '@env/environment'; |
2 | 3 | import { OpenLibraryRecord } from './model/open-library.model'; |
3 | 4 |
|
4 | 5 | @Component({ |
5 | 6 | selector: 'app-book', |
6 | 7 | imports: [], |
7 | 8 | template: ` |
8 | | - <div class="flex flex-col"> |
9 | | - <h1>{{ book().title }}</h1> |
10 | | - @if (book().author_name) { |
11 | | - <div><span class="font-bold">Auteurs:</span> {{ book().author_name.join(', ') }}</div> |
12 | | - } |
13 | | - @if (book().language) { |
14 | | - <div><span class="font-bold">Langues:</span> {{ book().language.join(', ') }}</div> |
15 | | - } |
| 9 | + <div class="bg-white rounded-xl shadow-md border border-gray-100 overflow-hidden hover:shadow-xl hover:border-[#1EA1CF]/30 transition-all duration-300 group h-full flex flex-col"> |
| 10 | + <!-- Book Cover --> |
| 11 | + <div class="relative bg-gradient-to-br from-gray-100 to-gray-200 h-64 flex items-center justify-center overflow-hidden"> |
| 12 | + @if (coverUrl()) { |
| 13 | + <img |
| 14 | + [src]="coverUrl()" |
| 15 | + [alt]="book().title" |
| 16 | + class="w-full h-full object-cover group-hover:scale-105 transition-transform duration-300" |
| 17 | + (error)="onImageError($event)" /> |
| 18 | + } @else { |
| 19 | + <div class="text-center p-6"> |
| 20 | + <i class="pi pi-book text-6xl text-gray-400 mb-3"></i> |
| 21 | + <p class="text-sm text-gray-500">Couverture non disponible</p> |
| 22 | + </div> |
| 23 | + } |
| 24 | + <!-- Overlay badge for publication year --> |
| 25 | + @if (book().first_publish_year) { |
| 26 | + <div class="absolute top-3 right-3 bg-[#1765A2] text-white px-3 py-1 rounded-full text-sm font-medium shadow-lg"> |
| 27 | + {{ book().first_publish_year }} |
| 28 | + </div> |
| 29 | + } |
| 30 | + </div> |
| 31 | +
|
| 32 | + <!-- Book Info --> |
| 33 | + <div class="p-5 flex-1 flex flex-col"> |
| 34 | + <!-- Title --> |
| 35 | + <h3 class="text-lg font-bold text-gray-800 mb-2 line-clamp-2 group-hover:text-[#1765A2] transition-colors"> |
| 36 | + {{ book().title }} |
| 37 | + </h3> |
| 38 | +
|
| 39 | + <!-- Authors --> |
| 40 | + @if (book().author_name && book().author_name.length > 0) { |
| 41 | + <div class="flex items-start gap-2 mb-3"> |
| 42 | + <i class="pi pi-user text-[#1EA1CF] text-sm mt-1 flex-shrink-0"></i> |
| 43 | + <p class="text-sm text-gray-600 line-clamp-2"> |
| 44 | + {{ book().author_name.join(', ') }} |
| 45 | + </p> |
| 46 | + </div> |
| 47 | + } |
| 48 | +
|
| 49 | + <!-- Metadata --> |
| 50 | + <div class="mt-auto space-y-2"> |
| 51 | + <!-- Languages --> |
| 52 | + @if (book().language && book().language.length > 0) { |
| 53 | + <div class="flex items-center gap-2"> |
| 54 | + <i class="pi pi-globe text-gray-400 text-xs"></i> |
| 55 | + <span class="text-xs text-gray-500"> |
| 56 | + {{ book().language.slice(0, 3).join(', ') }} |
| 57 | + @if (book().language.length > 3) { |
| 58 | + <span class="text-gray-400">+{{ book().language.length - 3 }}</span> |
| 59 | + } |
| 60 | + </span> |
| 61 | + </div> |
| 62 | + } |
| 63 | +
|
| 64 | + <!-- Publisher --> |
| 65 | + @if (book().publisher?.length) { |
| 66 | + <div class="flex items-center gap-2"> |
| 67 | + <i class="pi pi-building text-gray-400 text-xs"></i> |
| 68 | + <span class="text-xs text-gray-500 truncate"> |
| 69 | + {{ book().publisher?.[0] }} |
| 70 | + </span> |
| 71 | + </div> |
| 72 | + } |
| 73 | +
|
| 74 | + <!-- Edition count --> |
| 75 | + @if (book().edition_count && book().edition_count! > 1) { |
| 76 | + <div class="flex items-center gap-2"> |
| 77 | + <i class="pi pi-copy text-gray-400 text-xs"></i> |
| 78 | + <span class="text-xs text-gray-500"> |
| 79 | + {{ book().edition_count }} édition{{ book().edition_count! > 1 ? 's' : '' }} |
| 80 | + </span> |
| 81 | + </div> |
| 82 | + } |
| 83 | + </div> |
| 84 | + </div> |
16 | 85 | </div> |
17 | 86 | ` |
18 | 87 | }) |
19 | 88 | export class Book { |
20 | 89 | book = input.required<OpenLibraryRecord>(); |
| 90 | + |
| 91 | + // Compute cover URL from ISBN or cover_i |
| 92 | + coverUrl = computed(() => { |
| 93 | + const bookData = this.book(); |
| 94 | + |
| 95 | + // Try to get cover from cover_i (cover edition id) |
| 96 | + if (bookData.cover_i) { |
| 97 | + return `${environment.openLibraryCoverApiUrl}/b/id/${bookData.cover_i}-L.jpg`; |
| 98 | + } |
| 99 | + |
| 100 | + // Try to get cover from ISBN |
| 101 | + if (bookData.isbn && bookData.isbn.length > 0) { |
| 102 | + return `${environment.openLibraryCoverApiUrl}/b/isbn/${bookData.isbn[0]}-L.jpg`; |
| 103 | + } |
| 104 | + |
| 105 | + return null; |
| 106 | + }); |
| 107 | + |
| 108 | + onImageError(event: Event) { |
| 109 | + // Hide broken image |
| 110 | + (event.target as HTMLImageElement).style.display = 'none'; |
| 111 | + } |
21 | 112 | } |
0 commit comments