fix: update product ago dates during SPA navigation in watch mode

watch.py now returns human_created_timestamp, human_updated_timestamp,
and show_dates in the JSON response. watch.js updatePageContent() rebuilds
the .product-meta-dates element on each navigation so Created/Updated
dates reflect the current product instead of staying stale from initial load.
This commit is contained in:
russell@unturf.com 2026-03-04 12:35:13 -05:00
parent 49c2bdd22d
commit 31cc9c394a
2 changed files with 18 additions and 1 deletions

View file

@ -766,7 +766,21 @@
ogImage.setAttribute('content', data.thumbnail_url);
}
// Update view count
// Update meta dates and view count
var metaDatesEl = document.querySelector('.product-meta-dates');
if (metaDatesEl && data.show_dates) {
var datesText = 'Created ' + data.human_created_timestamp;
if (data.human_created_timestamp !== data.human_updated_timestamp) {
datesText += ' · Updated ' + data.human_updated_timestamp;
}
if (data.human_view_count) {
datesText += ' · <span class="product-view-count">' + escapeHtml(data.human_view_count) + '</span>';
}
metaDatesEl.innerHTML = datesText;
} else if (metaDatesEl && !data.show_dates) {
metaDatesEl.innerHTML = '';
}
var viewCountEl = document.querySelector('.product-view-count');
if (viewCountEl) {
viewCountEl.textContent = data.human_view_count || '';

View file

@ -213,6 +213,9 @@ def watch_json(request):
"file_size": file_size_str,
"view_count": product.view_count or 0,
"human_view_count": product.human_view_count,
"human_created_timestamp": product.human_created_timestamp,
"human_updated_timestamp": product.human_updated_timestamp,
"show_dates": request.shop.show_dates,
"related": related_data,
"ring": ring,
"is_mod": is_mod,