diff --git a/static/app.js b/static/app.js index add7b02..42f4917 100644 --- a/static/app.js +++ b/static/app.js @@ -44,8 +44,30 @@ function renderTable() { // Body rows const tbody = document.createElement('tbody'); if (!data.guestNames) data.guestNames = {}; - // Show most recent date at the top - [...data.dates].slice().reverse().forEach((date, rowIdx) => { + // Custom order: last played date (<= today) on top, next date (> today) second, others after + const today = new Date(); + // Parse dates as DD/MM/YY + function parseDate(str) { + const [d, m, y] = str.split('/').map(Number); + // Assume 20xx for years < 100 + return new Date(2000 + y, m - 1, d); + } + const pastDates = data.dates.filter(date => parseDate(date) <= today); + const futureDates = data.dates.filter(date => parseDate(date) > today); + // Find most recent past date (last match) + const lastMatch = pastDates.length > 0 ? pastDates.reduce((a, b) => parseDate(a) > parseDate(b) ? a : b) : null; + // Find next match (soonest future date) + const nextMatch = futureDates.length > 0 ? futureDates.reduce((a, b) => parseDate(a) < parseDate(b) ? a : b) : null; + // Remaining dates + const otherDates = data.dates.filter(date => date !== lastMatch && date !== nextMatch); + // Sort remaining dates descending (most recent first) + otherDates.sort((a, b) => parseDate(b) - parseDate(a)); + // Compose ordered list + const orderedDates = []; + if (lastMatch) orderedDates.push(lastMatch); + if (nextMatch) orderedDates.push(nextMatch); + orderedDates.push(...otherDates); + orderedDates.forEach((date, rowIdx) => { const tr = document.createElement('tr'); // Date cell const dateTd = document.createElement('td');