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() {
|
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()
|
||||||
}
|
}
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue