fix closest day
This commit is contained in:
parent
7879d17d54
commit
16d8d4f422
1 changed files with 9 additions and 11 deletions
|
|
@ -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()
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue