fix closest day

This commit is contained in:
isUnknown 2024-11-07 15:41:13 +01:00
parent 7879d17d54
commit 16d8d4f422

View file

@ -31,21 +31,19 @@
scrollToNextClosestDate() { scrollToNextClosestDate() {
const nodes = document.querySelectorAll('.sessions [data-date]'); const nodes = document.querySelectorAll('.sessions [data-date]');
const today = new Date(); const today = new Date();
today.setHours(0, 0, 0, 0); // On ne garde que la date
const nodesWithDates = Array.from(nodes).map(node => {
const dateStr = node.getAttribute('data-date');
const date = new Date(dateStr);
return { node, date };
}).filter(({ date }) => date >= today);
if (nodesWithDates.length === 0) return; const nextNode = Array.from(nodes).find(node => {
const date = new Date(node.getAttribute('data-date'));
const nextClosestNode = nodesWithDates.reduce((closest, current) => { date.setHours(0, 0, 0, 0);
return current.date < closest.date ? current : closest; return date >= today;
}); });
nextClosestNode.node.scrollIntoView({ behavior: 'smooth' }); if (nextNode) {
nextNode.scrollIntoView({ behavior: 'smooth' });
}
}, },
getFilter(string) { getFilter(string) {
return string.split('—')[1].trim() return string.split('—')[1].trim()
} }