-
Notifications
You must be signed in to change notification settings - Fork 77
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implement infinite scroll in dashboard (#501)
* inifinite scroll * remove time select and add button * use new endpoint for infinite loading * fix dongleid change to init routes * preserve events for route * fix bugs * fix time select not display routes events * add a bottom margin to end of drive message * use map to store all fetched location and events
- Loading branch information
Showing
11 changed files
with
234 additions
and
144 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
import React, { useEffect, useRef } from 'react'; | ||
|
||
const ScrollIntoView = ({ onInView, children }) => { | ||
const elementRef = useRef(null); | ||
const hasDispatched = useRef(false); | ||
|
||
useEffect(() => { | ||
const options = { | ||
root: null, // relative to the viewport | ||
rootMargin: '0px', | ||
threshold: 0.1 // 10% of the target's visibility | ||
}; | ||
|
||
const observer = new IntersectionObserver((entries) => { | ||
entries.forEach(entry => { | ||
if (entry.isIntersecting && !hasDispatched.current) { | ||
onInView(); | ||
hasDispatched.current = true | ||
} | ||
}); | ||
}, options); | ||
|
||
if (elementRef.current) { | ||
observer.observe(elementRef.current); | ||
} | ||
|
||
return () => { | ||
if (observer && elementRef.current) { | ||
observer.unobserve(elementRef.current); | ||
} | ||
}; | ||
}, [onInView]); | ||
|
||
return ( | ||
<div ref={elementRef}> | ||
{children} | ||
</div> | ||
); | ||
}; | ||
|
||
export default ScrollIntoView; |
Oops, something went wrong.