diff --git a/templates/watchlist.gohtml b/templates/watchlist.gohtml index cf46128..b09415e 100644 --- a/templates/watchlist.gohtml +++ b/templates/watchlist.gohtml @@ -37,7 +37,7 @@
{{range $.AllEntries}} -
+
{{.DisplayTitle}} @@ -136,8 +136,8 @@ const titleB = b.querySelector('h3').textContent.toLowerCase().trim() comparison = titleA.localeCompare(titleB) } else { - const dateA = new Date(a.dataset.createdAt || 0).getTime() - const dateB = new Date(b.dataset.createdAt || 0).getTime() + const dateA = parseInt(a.dataset.updatedAt || 0) + const dateB = parseInt(b.dataset.updatedAt || 0) comparison = dateA - dateB } return sortOrderDesc ? -comparison : comparison @@ -147,5 +147,10 @@ grid.appendChild(item) }) } + + // Ensure items are sorted correctly on initial load + window.addEventListener('DOMContentLoaded', () => { + sortItems() + }) {{end}} diff --git a/templates/watchlist_partial.gohtml b/templates/watchlist_partial.gohtml index 9f14a1d..3519bf8 100644 --- a/templates/watchlist_partial.gohtml +++ b/templates/watchlist_partial.gohtml @@ -41,7 +41,7 @@
{{range $entries}} -
+
{{.DisplayTitle}} @@ -139,8 +139,8 @@ const titleB = b.querySelector('h3').textContent.toLowerCase() comparison = titleA.localeCompare(titleB) } else { - const dateA = new Date(a.dataset.createdAt || 0).getTime() - const dateB = new Date(b.dataset.createdAt || 0).getTime() + const dateA = parseInt(a.dataset.updatedAt || 0) + const dateB = parseInt(b.dataset.updatedAt || 0) comparison = dateA - dateB } return sortOrderDesc ? -comparison : comparison @@ -151,5 +151,14 @@ }) }) } + + // Handle HTMX partial swaps + if (document.readyState === 'complete') { + sortItems() + } else { + window.addEventListener('DOMContentLoaded', () => { + sortItems() + }) + } {{end}} \ No newline at end of file