Scroll to current date V2
This commit is contained in:
parent
39da8ee184
commit
3377970fea
@ -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');
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user