Home 'Disponibili' real count + responsive related-books#288
Conversation
…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.
|
Warning Review limit reached
Next review available in: 31 minutes Enable usage-based reviews in Billing to review now. Otherwise, wait until the next included review is available. How can I continue?After more reviews become available, a review can be triggered using the 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 configurationConfiguration used: Path: .coderabbit.yaml Review profile: ASSERTIVE Plan: Pro Plus Run ID: 📒 Files selected for processing (4)
📝 WalkthroughWalkthroughIl 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. ChangesCatalogo e libri correlati
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
Possibly related PRs
Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
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. Comment |
There was a problem hiding this comment.
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
📒 Files selected for processing (3)
app/Controllers/FrontendController.phpapp/Views/frontend/book-detail.phpapp/Views/frontend/home.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.
Code reviewBranch: Found 5 findings across all lanes:
Deep lane — correctness & security✓ Auto-fixable (1)
Details and fix proposalsF002 — 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: Evidence:
Approach: Pure-CSS one-liner: only one row is ever visible, so the row gap serves no visual purpose. Files to modify:
Verification:
Edge cases to preserve:
Latest fix attempt (fixrun_20260724T121127Zdf00b4): fixed and verified Fix runsRun
|
| 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.
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.
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 returnspagination.available_books(COUNT of the same filter set restricted tocopie_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/catalogo→total_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 Bootstrapcol-lg-4row. 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) fromPluginManager.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à
Correzioni