1
0
Fork 0

Auto-scroll to selected author

This commit is contained in:
Lim Chee Aun 2024-02-29 21:01:31 +08:00
parent 631333ba9e
commit 1bf8616957

View file

@ -515,6 +515,36 @@ function Catchup() {
authors,
]);
const prevSelectedAuthorMissing = useRef(false);
useEffect(() => {
console.log({
prevSelectedAuthorMissing,
selectedAuthor,
authors,
});
let timer;
if (selectedAuthor) {
if (authors[selectedAuthor]) {
if (prevSelectedAuthorMissing.current) {
timer = setTimeout(() => {
authorsListParent.current
.querySelector(`[data-author="${selectedAuthor}"]`)
?.scrollIntoView({
behavior: 'smooth',
inline: 'center',
});
}, 500);
prevSelectedAuthorMissing.current = false;
}
} else {
prevSelectedAuthorMissing.current = true;
}
}
return () => {
clearTimeout(timer);
};
}, [selectedAuthor, authors]);
return (
<div
ref={scrollableRef}
@ -907,6 +937,7 @@ function Catchup() {
{authorCountsList.map((author) => (
<label
class="filter-author"
data-author={author}
key={`${author}-${authorCounts[author]}`}
// Preact messed up the order sometimes, need additional key besides just `author`
// https://github.com/preactjs/preact/issues/2849