mirror of
https://github.com/cheeaun/phanpy.git
synced 2025-01-23 17:16:26 +01:00
Auto-scroll to selected author
This commit is contained in:
parent
631333ba9e
commit
1bf8616957
1 changed files with 31 additions and 0 deletions
|
@ -515,6 +515,36 @@ function Catchup() {
|
||||||
authors,
|
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 (
|
return (
|
||||||
<div
|
<div
|
||||||
ref={scrollableRef}
|
ref={scrollableRef}
|
||||||
|
@ -907,6 +937,7 @@ function Catchup() {
|
||||||
{authorCountsList.map((author) => (
|
{authorCountsList.map((author) => (
|
||||||
<label
|
<label
|
||||||
class="filter-author"
|
class="filter-author"
|
||||||
|
data-author={author}
|
||||||
key={`${author}-${authorCounts[author]}`}
|
key={`${author}-${authorCounts[author]}`}
|
||||||
// Preact messed up the order sometimes, need additional key besides just `author`
|
// Preact messed up the order sometimes, need additional key besides just `author`
|
||||||
// https://github.com/preactjs/preact/issues/2849
|
// https://github.com/preactjs/preact/issues/2849
|
||||||
|
|
Loading…
Reference in a new issue