fix: preload player rating history to fix first-click chart render (#10) #15

Merged
shcizo merged 2 commits from fix/preload-player-history-10 into main 2026-05-22 12:59:28 +02:00
Owner

Summary

  • Preloads each player's full rating history server-side via a new bulk query (getAllRatingHistoriesFromDB), so views/partials/ratings-table.ejs can include player-history inline per row instead of lazy-loading it on first expansion.
  • Broadens htmx:afterSwap chart init (renamed setupAfterTableSwap, extracted initChartsIn with a data-charted guard) so charts render on the initial #ratings-table swap as well as on per-row refreshes.
  • Centralizes the "15 Jan, 2025" date formatting in a single formatDisplayDate helper, replacing three inline toLocaleDateString duplicates.

The per-row /partials/player-history/:pdgaNumber endpoint is kept — still used by the manual "refresh rating history" flow.

Closes #10

Test plan

  • Hard reload /, click any player row → chart renders on the first click (was previously only on the second).
  • Network tab shows no GET /partials/player-history/... request when expanding rows.
  • Collapse and re-expand a row → chart still renders, no duplicates, no console errors.
  • Click the per-row refresh icon → table re-loads → expanding the same row still renders the chart.
  • Click "Refresh rating history" inside an expanded row → chart re-renders via the kept endpoint.
  • Player with no history → "No rating history available" branch renders cleanly, no JS error.
  • DevTools console clean (no Error rendering chart: messages).
## Summary - Preloads each player's full rating history server-side via a new bulk query (`getAllRatingHistoriesFromDB`), so `views/partials/ratings-table.ejs` can include `player-history` inline per row instead of lazy-loading it on first expansion. - Broadens `htmx:afterSwap` chart init (renamed `setupAfterTableSwap`, extracted `initChartsIn` with a `data-charted` guard) so charts render on the initial `#ratings-table` swap as well as on per-row refreshes. - Centralizes the `"15 Jan, 2025"` date formatting in a single `formatDisplayDate` helper, replacing three inline `toLocaleDateString` duplicates. The per-row `/partials/player-history/:pdgaNumber` endpoint is kept — still used by the manual "refresh rating history" flow. Closes #10 ## Test plan - [ ] Hard reload `/`, click any player row → chart renders on the **first** click (was previously only on the second). - [ ] Network tab shows no `GET /partials/player-history/...` request when expanding rows. - [ ] Collapse and re-expand a row → chart still renders, no duplicates, no console errors. - [ ] Click the per-row refresh icon → table re-loads → expanding the same row still renders the chart. - [ ] Click "Refresh rating history" inside an expanded row → chart re-renders via the kept endpoint. - [ ] Player with no history → "No rating history available" branch renders cleanly, no JS error. - [ ] DevTools console clean (no `Error rendering chart:` messages).
shcizo added 2 commits 2026-05-22 12:59:15 +02:00
shcizo merged commit c6ac174921 into main 2026-05-22 12:59:28 +02:00
Sign in to join this conversation.