mirror of
https://github.com/omnivore-app/omnivore.git
synced 2026-03-11 08:54:26 +00:00
Do debouncing in scrollWatcher instead of using lodash
This commit is contained in:
parent
4d2698145a
commit
2192c563a7
1 changed files with 1 additions and 18 deletions
|
|
@ -8,7 +8,6 @@ import { MutableRefObject, useEffect, useMemo, useRef, useState } from 'react'
|
|||
import { Tweet } from 'react-twitter-widgets'
|
||||
import { render } from 'react-dom'
|
||||
import { isDarkTheme } from '../../../lib/themeUpdater'
|
||||
import debounce from 'lodash/debounce'
|
||||
import { ArticleMutations } from '../../../lib/articleActions'
|
||||
|
||||
export type ArticleProps = {
|
||||
|
|
@ -38,22 +37,6 @@ export function Article(props: ArticleProps): JSX.Element {
|
|||
|
||||
useReadingProgressAnchor(articleContentRef, setReadingAnchorIndex)
|
||||
|
||||
const debouncedSetReadingProgress = useMemo(
|
||||
() =>
|
||||
debounce((readingProgress: number) => {
|
||||
setReadingProgress(readingProgress)
|
||||
}, 2000),
|
||||
[]
|
||||
)
|
||||
|
||||
// Stop the invocation of the debounced function
|
||||
// after unmounting
|
||||
useEffect(() => {
|
||||
return () => {
|
||||
debouncedSetReadingProgress.cancel()
|
||||
}
|
||||
}, [])
|
||||
|
||||
useEffect(() => {
|
||||
;(async () => {
|
||||
if (!readingProgress) return
|
||||
|
|
@ -99,7 +82,7 @@ export function Article(props: ArticleProps): JSX.Element {
|
|||
window.scrollY,
|
||||
window.document.scrollingElement.scrollHeight
|
||||
)
|
||||
debouncedSetReadingProgress(adjustedReadingProgress * 100)
|
||||
setReadingProgress(adjustedReadingProgress * 100)
|
||||
}
|
||||
}, 2500)
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue