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

This commit is contained in:
Samuel Enocsson
2026-05-22 11:41:38 +02:00
parent 3cfdc305ec
commit a63da6f3ca
5 changed files with 69 additions and 18 deletions
+21 -13
View File
@@ -26,23 +26,31 @@ function applyDeltaPill(pillEl, value) {
pillEl.appendChild(numSpan);
}
function initChartsIn(rootEl) {
rootEl.querySelectorAll('.player-chart').forEach(function(container) {
if (container.dataset.charted === 'true') return;
if (!container.dataset.history) return;
try {
const history = JSON.parse(container.dataset.history);
createRatingChart(container, history);
container.dataset.charted = 'true';
} catch (e) {
console.error('Error rendering chart:', e);
}
});
}
function setupTooltipsAfterSwap() {
document.body.addEventListener('htmx:afterSwap', function(event) {
if (event.detail.target.id === 'ratings-table') {
initRatingsTooltips();
}
// After player history partial loads, render the chart
const target = event.detail.target;
if (target.id === 'ratings-table') {
initRatingsTooltips();
initChartsIn(target); // initial table render — chart any pre-loaded .player-chart
return;
}
// refreshRatingHistory still re-fetches into #history-content-<id>
if (target.id && target.id.startsWith('history-content-')) {
const container = target.querySelector('.player-chart, .chart-container');
if (container && container.dataset.history) {
try {
const history = JSON.parse(container.dataset.history);
createRatingChart(container, history);
} catch (e) {
console.error('Error rendering chart:', e);
}
}
initChartsIn(target);
}
});
}