Merge branch 'main' of https://github.com/Discours/discoursio-webapp into feature/sse-connect

This commit is contained in:
Untone 2023-10-17 17:08:13 +03:00
commit 4104bac44e
2 changed files with 3 additions and 8 deletions

View File

@ -16,12 +16,7 @@ interface Props {
const isInViewport = (el: Element): boolean => {
const rect = el.getBoundingClientRect()
return (
rect.top >= 0 &&
rect.left >= 0 &&
rect.bottom <= (window.innerHeight || document.documentElement.clientHeight) &&
rect.right <= (window.innerWidth || document.documentElement.clientWidth)
)
return rect.top <= DEFAULT_HEADER_OFFSET
}
const scrollToHeader = (element) => {
window.scrollTo({
@ -57,7 +52,7 @@ export const TableOfContents = (props: Props) => {
const debouncedUpdateHeadings = debounce(updateHeadings, 500)
const updateActiveHeader = throttle(() => {
const newActiveIndex = headings().findIndex((heading) => isInViewport(heading))
const newActiveIndex = headings().findLastIndex((heading) => isInViewport(heading))
setActiveHeaderIndex(newActiveIndex)
}, 50)

View File

@ -13,6 +13,6 @@
"resolveJsonModule": true,
"skipLibCheck": true,
"isolatedModules": true,
"lib": ["ES2021", "dom"]
"lib": ["es2023", "dom"]
}
}