Skip to content

Commit 8d3bc3e

Browse files
committed
Show title when hovering top author book covers
1 parent c58c930 commit 8d3bc3e

4 files changed

Lines changed: 18 additions & 7 deletions

File tree

backend/app/routers/statistics.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -489,7 +489,7 @@ def get_statistics(
489489
for author_name in top_author_names:
490490
max_slots = min(5, author_counts[author_name])
491491
cover_rows = session.exec(
492-
select(Book.id, Book.reading_status, Book.cover_url)
492+
select(Book.id, Book.title, Book.reading_status, Book.cover_url)
493493
.where(
494494
Book.user_id == current_user.id,
495495
Book.author == author_name,
@@ -499,14 +499,14 @@ def get_statistics(
499499
.limit(max_slots)
500500
).all()
501501
results = [
502-
TopAuthorCover(book_id=book_id, reading_status=reading_status, cover_url=cover_url)
503-
for book_id, reading_status, cover_url in cover_rows
502+
TopAuthorCover(book_id=book_id, title=title, reading_status=reading_status, cover_url=cover_url)
503+
for book_id, title, reading_status, cover_url in cover_rows
504504
if book_id is not None
505505
]
506506
remaining = max_slots - len(results)
507507
if remaining > 0:
508508
no_cover_rows = session.exec(
509-
select(Book.id, Book.reading_status, Book.cover_url)
509+
select(Book.id, Book.title, Book.reading_status, Book.cover_url)
510510
.where(
511511
Book.user_id == current_user.id,
512512
Book.author == author_name,
@@ -516,8 +516,8 @@ def get_statistics(
516516
.limit(remaining)
517517
).all()
518518
results.extend(
519-
TopAuthorCover(book_id=book_id, reading_status=reading_status, cover_url=cover_url)
520-
for book_id, reading_status, cover_url in no_cover_rows
519+
TopAuthorCover(book_id=book_id, title=title, reading_status=reading_status, cover_url=cover_url)
520+
for book_id, title, reading_status, cover_url in no_cover_rows
521521
if book_id is not None
522522
)
523523
covers_by_author[author_name] = results

backend/app/schemas.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,7 @@ class TopAuthor(SQLModel):
223223
class TopAuthorCover(SQLModel):
224224
"""Cover reference for a book by a top author."""
225225
book_id: int
226+
title: str
226227
reading_status: ReadingStatus
227228
cover_url: str | None
228229

frontend/src/lib/types.ts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -140,6 +140,7 @@ export interface TopAuthor {
140140

141141
export interface TopAuthorCover {
142142
book_id: number;
143+
title: string;
143144
reading_status: ReadingStatus;
144145
cover_url: string;
145146
}

frontend/src/routes/statistics/+page.svelte

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,16 @@
411411
{$_('statistics.booksCount', { values: { count: author.book_count } })}
412412
</div>
413413
{#if author.covers.length > 0}
414+
{@const hoveredCover = author.covers.find(c => c.book_id === activeBookId)}
415+
<div class="h-5 overflow-hidden mb-1">
416+
<p
417+
class="text-xs font-medium truncate transition-all duration-300 {hoveredCover ? 'opacity-100 translate-y-0' : 'opacity-0 translate-y-1'}"
418+
title={hoveredCover?.title ?? ''}
419+
>{hoveredCover?.title ?? ''}</p>
420+
</div>
414421
<!-- Covers overlap with -ml-3 to save space, pl-3 keeps the first cover fully visible. -->
415422
<div
416-
class="flex items-end overflow-hidden pt-4 pb-1 pl-3"
423+
class="flex items-end overflow-hidden pt-2 pb-1 pl-3"
417424
role="group"
418425
aria-label={$_('statistics.coversForAuthor', { values: { author: author.author } })}
419426
ontouchmove={(e) => {
@@ -436,6 +443,8 @@
436443
style:z-index={activeBookId === cover.book_id ? 50 : coverIdx + 1}
437444
data-book-id={cover.book_id}
438445
onclick={() => openCoverBook(cover.book_id)}
446+
onmouseenter={() => { activeBookId = cover.book_id; }}
447+
onmouseleave={() => { activeBookId = null; }}
439448
>
440449
<img
441450
src={cover.cover_url ?? '/placeholder-cover.svg'}

0 commit comments

Comments
 (0)