Skip to content

Home 'Disponibili' real count + responsive related-books#288

Merged
fabiodalez-dev merged 4 commits into
mainfrom
fix/home-available-count-and-responsive-related
Jul 24, 2026
Merged

Home 'Disponibili' real count + responsive related-books#288
fabiodalez-dev merged 4 commits into
mainfrom
fix/home-available-count-and-responsive-related

Conversation

@fabiodalez-dev

@fabiodalez-dev fabiodalez-dev commented Jul 23, 2026

Copy link
Copy Markdown
Owner

Two reported frontend bugs, both fixed and deployed to bibliotecafemminista.

1. 🐛 Home hero "Disponibili" showed 📚 instead of a number

loadStats() explicitly set the element to the emoji because the catalog API had no available-books figure. catalogAPI() now returns pagination.available_books (COUNT of the same filter set restricted to copie_disponibili > 0), and the JS renders it (falling back to the total on an older backend; the error path shows an em-dash).
Verified in prod: /api/catalogototal_books: 157, available_books: 150; the live home hero shows Disponibili 150.

2. 🐛 Related books ("Potrebbero interessarti") were hard-capped at 3

Fixed $limit = 3 + a Bootstrap col-lg-4 row. Now fetches up to 6 and renders them in a responsive one-row grid (repeat(auto-fill, minmax(170px, 1fr)) + grid-auto-rows: 0 + overflow: hidden), so the number shown adapts to the viewport instead of a fixed 3.
Verified locally: 6 cards at 1400px, 3 at 768px, 1 at 380px, with the overflow rows clipped.

php -l + PHPStan clean. Deployed (with backup) to the production install; opcache reset.

Note: on the local PHP 8.5 dev box the catalog API response is polluted by a ReflectionProperty::setAccessible() deprecation (a no-op since 8.1) from PluginManager.php:1723, which breaks the home fetch locally only — prod runs 8.3 with display_errors off, so the JSON is clean. Worth removing that call separately for forward-compat.

Summary by CodeRabbit

  • Nuove funzionalità

    • Aggiunto il conteggio dei libri disponibili nella paginazione del catalogo.
    • La sezione dei libri correlati può ora mostrare fino a 6 suggerimenti.
    • Introdotta una griglia responsive per visualizzare meglio i libri correlati su schermi di diverse dimensioni.
  • Correzioni

    • Le statistiche della home page mostrano correttamente i libri disponibili.
    • In caso di errore nel caricamento, le statistiche vengono sostituite da un indicatore neutro invece di messaggi poco chiari.

…ks count

Two reported frontend bugs:

1. Home hero "Disponibili" stat showed a 📚 emoji instead of a number. The
   loadStats() JS explicitly set the element to the emoji because the catalog
   API exposed no available-books figure. catalogAPI() now returns
   pagination.available_books (COUNT of the same filter set restricted to
   copie_disponibili > 0), and the JS renders it (falling back to the total on
   an older backend). The error path now shows an em-dash instead of a stray ✓.

2. The single-book "Potrebbero interessarti" section was hard-capped at 3
   related books (fixed $limit = 3 + a Bootstrap col-lg-4 row). It now fetches
   up to 6 and renders them in a responsive one-row grid (repeat(auto-fill,
   minmax(170px,1fr)) with grid-auto-rows:0 + overflow:hidden), so the number
   shown adapts to the viewport — ~6 desktop / 3 tablet / 1–2 phone — instead of
   a fixed 3.

Verified: available_books is returned by the API (e.g. 56/124) and read by the
home JS; the related grid shows 6 at 1400px, 3 at 768px and 1 at 380px with the
overflow rows clipped. php -l clean on all three files.
@coderabbitai

coderabbitai Bot commented Jul 23, 2026

Copy link
Copy Markdown

Review Change Stack

Warning

Review limit reached

@fabiodalez-dev, you've reached your PR review limit, so we couldn't start this review.

Next review available in: 31 minutes

Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available.
You're only billed for reviews past your plan's rate limits ($0.25/file).

How can I continue?

After more reviews become available, a review can be triggered using the @coderabbitai review command as a PR comment. Alternatively, push new commits to this PR.

To avoid repeated limits, reduce automatic review volume by pausing incremental auto-reviews earlier, using label-based review opt-in, excluding WIP or generated PR titles, or requesting reviews manually when the PR is ready. If your team needs uninterrupted high-volume reviews, an organization admin can enable usage-based reviews.

How do review limits work?

CodeRabbit enforces per-developer PR review limits for each organization. Most developers receive the normal plan review availability.

For paid Pro and Pro+ PR reviews, CodeRabbit uses adaptive limits for sustained high-volume activity. When a developer's recent PR review activity reaches the 95th percentile or higher among CodeRabbit users, additional reviews become available more gradually as earlier reviews age out of the rolling window.

Please refer docs for additional details.

Review details
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: 4a9f5ef7-106e-4ccc-a939-bf527f3e70d7

📥 Commits

Reviewing files that changed from the base of the PR and between 8c29a93 and 0a7c999.

📒 Files selected for processing (4)
  • app/Controllers/FrontendController.php
  • app/Views/frontend/book-detail.php
  • app/Views/frontend/home.php
  • tests/home-available-count-288.unit.php
📝 Walkthrough

Walkthrough

Il catalogo ora espone il numero di libri disponibili. La pagina dettaglio seleziona fino a sei libri correlati e li dispone in una griglia responsive; la home aggiorna le statistiche usando il nuovo campo API.

Changes

Catalogo e libri correlati

Layer / File(s) Summary
Conteggio libri disponibili
app/Controllers/FrontendController.php, app/Views/frontend/home.php
catalogAPI() aggiunge pagination.available_books usando i filtri correnti e le copie disponibili; la home visualizza il valore, con fallback e gestione dell’errore.
Libri correlati e griglia responsive
app/Controllers/FrontendController.php, app/Views/frontend/book-detail.php
Il limite dei libri correlati passa da 3 a 6 e il markup Bootstrap viene sostituito da una griglia CSS responsive con contenitore fino a 1320px.

Estimated code review effort: 3 (Moderate) | ~20 minutes

Sequence Diagram(s)

sequenceDiagram
  participant Home
  participant catalogAPI
  participant Database
  Home->>catalogAPI: richiede statistiche catalogo
  catalogAPI->>Database: conta i libri filtrati disponibili
  Database-->>catalogAPI: available_books
  catalogAPI-->>Home: restituisce pagination.available_books
  Home->>Home: aggiorna i contatori
Loading

Possibly related PRs

Suggested reviewers: fabiodalez

🚥 Pre-merge checks | ✅ 5
✅ Passed checks (5 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed Il titolo riassume correttamente i due cambi principali: conteggio reale di "Disponibili" nella home e sezione related-books responsive.
Docstring Coverage ✅ Passed No functions found in the changed files to evaluate docstring coverage. Skipping docstring coverage check.
Linked Issues check ✅ Passed Check skipped because no linked issues were found for this pull request.
Out of Scope Changes check ✅ Passed Check skipped because no linked issues were found for this pull request.
✨ Finishing Touches
🧪 Generate unit tests (beta)
  • Create PR with unit tests
  • Commit unit tests in branch fix/home-available-count-and-responsive-related

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share

Comment @coderabbitai help to get the list of available commands.

@coderabbitai coderabbitai Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Actionable comments posted: 2

🤖 Prompt for all review comments with AI agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

Inline comments:
In `@app/Controllers/FrontendController.php`:
- Around line 587-597: Update the available-books query flow around
$available_stmt so prepare(), execute(), and get_result() failures are detected
and propagated through an HTTP error or explicit error flag instead of being
converted to zero availability. Preserve the existing total-count fallback only
when the backend does not provide the availability field, not when the
availability query fails.

In `@app/Views/frontend/book-detail.php`:
- Around line 1481-1506: Update the related-books rendering and resize behavior
associated with .related-books-grid and .related-book-cell so cards beyond the
first visible row are actually excluded from tab navigation and the
accessibility tree, using hidden and/or inert rather than only CSS overflow.
Recalculate which cards belong to the first row on resize and apply or remove
that state so the visible card count remains responsive.
🪄 Autofix (Beta)

Fix all unresolved CodeRabbit comments on this PR:

  • Push a commit to this branch (recommended)
  • Create a new PR with the fixes

ℹ️ Review info
⚙️ Run configuration

Configuration used: Path: .coderabbit.yaml

Review profile: ASSERTIVE

Plan: Pro Plus

Run ID: de709ee3-685b-462d-845e-7cc3fe280a0b

📥 Commits

Reviewing files that changed from the base of the PR and between aae6353 and 8c29a93.

📒 Files selected for processing (3)
  • app/Controllers/FrontendController.php
  • app/Views/frontend/book-detail.php
  • app/Views/frontend/home.php

Comment thread app/Controllers/FrontendController.php Outdated
Comment thread app/Views/frontend/book-detail.php
…ipped related cards

Two Major review findings on the home available-count + responsive related grid:

- FrontendController::catalogAPI() silently left available_books = 0 when the
  count query's prepare()/execute()/get_result() failed, so the home hero would
  show a real-looking "0 disponibili" on a DB error. It now defaults to null,
  checks each step, logs the failure via SecureLogger, and emits null — the home
  JS already falls back to total_books on null, so a transient count failure
  degrades to the total instead of a misleading zero (and never 500s the whole
  listing over a secondary count).

- book-detail.php related grid clipped rows past the first with
  overflow:hidden + grid-auto-rows:0, but the clipped cards stayed in the DOM,
  the tab order and the accessibility tree — keyboard/screen-reader users could
  reach cards they can't see. Added a small script that marks every cell below
  the first row `inert` + aria-hidden (+ tabindex=-1 on its links as a fallback
  for browsers without `inert`), recomputed on resize. Layout is untouched, so
  offsetTop stays accurate without oscillation.

Verified in a real browser against a seeded 6-related-book page: 1400px → 6
visible / 0 inert; 760px → 3 visible / 3 inert; 390px → 1 visible / 5 inert,
with the hidden cards' links pulled from the tab order at every width. php -l +
PHPStan level 5 clean.
@fabiodalez-dev

fabiodalez-dev commented Jul 24, 2026

Copy link
Copy Markdown
Owner Author

Code review

Branch: fix/home-available-count-and-responsive-relatedmain
PR: #288 (open)
Review ID: rev_20260724T104300Z30a9d7
Base freshness: local main was behind origin/main at run start; fast-forwarded before review
Sub-agent tokens: 1,360,449 across 12 invocations

Found 5 findings across all lanes:

  • Deep lane (correctness/security): 1 resolved

Deep lane — correctness & security

✓ Auto-fixable (1)

# Score Impact File Issue Status
F002 75 correctness app/Views/frontend/book-detail.php:1493-1501 grid-auto-rows:0 collapses overflow rows to height 0 but the 1.5rem row gap still renders between every pair of consecutive tracks including zero-height ones, leaving trailing whitespace below the visible row proportional to the number of hidden rows. ✓ fixed and verified (0a7c999)
Details and fix proposals

F002 — grid-auto-rows:0 collapses overflow rows to height 0 but the 1.5rem row gap still renders between every pair of consecutive tracks including zero-height ones, leaving trailing whitespace below the visible row proportional to the number of hidden rows.

File: app/Views/frontend/book-detail.php:1493-1501
Score: 75 (strong)

Evidence:

  • book-detail.php:1496 gap:1.5rem sets row-gap AND column-gap; CSS Grid does NOT collapse gaps between zero-height tracks
  • Container height = H(row1) + (N-1)*24px; overflow:hidden clips track content but not the container's own gap-inflated height
  • With 6 cards: 768px/3col -> 24px trailing; 576px/2col -> 48px; 375px/1col -> ~120px whitespace below the single visible card
  • The 1400px empirical anchor (2px) is the one-row case — consistent, not contradictory
  • display:none on inert cells would break the a11y script: display:none reports offsetTop 0, defeating clipped-cell detection at 2450-2452

Approach: Pure-CSS one-liner: only one row is ever visible, so the row gap serves no visual purpose.

Files to modify:

  • app/Views/frontend/book-detail.php — Line 1496: replace gap: 1.5rem; with column-gap: 1.5rem; row-gap: 0; (why: Removes (hidden_rows x 24px) trailing whitespace on wrapped/mobile layouts while preserving horizontal gutters and the offsetTop-based inert detection)

Verification:

  • At 768px and 375px, scrollHeight of .related-books-grid ~= visible row height (no trailing gap)
  • inert marking still applies to clipped cells at 760/390px

Edge cases to preserve:

  • Horizontal 1.5rem gutters unchanged
  • a11y script offsetTop detection keeps working (rows still laid out)

Latest fix attempt (fixrun_20260724T121127Zdf00b4): fixed and verified

Fix runs

Run fixrun_20260724T121127Zdf00b4 — 2026-07-24T12:24:45Z

  • Outcomes: 4 fixed and verified
  • Commits: 0a7c999
Finding Group Outcome phase_9_finding
F001 FG-1 ✓ fixed and verified
F002 FG-2 ✓ fixed and verified
F003 FG-2 ✓ fixed and verified
F005 FG-2 ✓ fixed and verified

🤖 Generated with Adam's Claude Code Review Command

Fix groups (committed):
- [FG-1] F001 — FrontendController.php, home.php, home-available-count-288.unit.php: verified.
  Gate the available-books COUNT behind ?with_stats=1 so the live catalog
  search/filter path no longer pays a discarded aggregate per keystroke;
  only the home hero requests it. New real-controller unit test (7/7)
  asserts the count with the flag, null without, and available < total
  with a seeded zero-copy book — guarding the ?? fallback from masking a
  mistyped flag.
- [FG-2] F002+F003+F005 — book-detail.php: verified.
  F002: column-gap 1.5rem / row-gap 0 removes the trailing whitespace the
  zero-height clipped rows' gaps produced (up to ~120px on phones).
  F003: <=480px the related grid becomes a horizontal scroll-snap carousel
  (80% card basis leaves a peek affordance); the a11y script detects the
  scroll mode (overflowX auto) and clears inert/aria-hidden/tabindex.
  F005: <noscript> override (overflow visible, auto rows, row-gap
  restored) so JS-off users see all cards stacked instead of clipped-but-
  focusable ghosts.

Post-fix review: 2/2 groups verified complete; 0 partial; 0 reverted.
@fabiodalez-dev
fabiodalez-dev merged commit c43bafd into main Jul 24, 2026
6 checks passed
fabiodalez-dev added a commit that referenced this pull request Jul 24, 2026
The What's New section only described the Danish-language PR; this release
also bundles bulk loan extension (#281), the mobile catalogue language
filter (#282), the home available-count + responsive related-books fix
(#288), Book Club external-book reconciliation (#138), PHP 8.5 compat
(#289), and the genre-key rename (#286/#290). Documented each user-facing
change.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant