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