mirror of
https://github.com/supermemoryai/supermemory.git
synced 2026-05-20 00:56:41 +00:00
added logic to clear old timeout before creating new one (prevents accumulation when nodes are selected rapidly, ex. slideshow)
This commit is contained in:
parent
97599c42ef
commit
b645d18342
1 changed files with 16 additions and 3 deletions
|
|
@ -536,6 +536,7 @@ export const MemoryGraph = ({
|
|||
|
||||
// Slideshow logic - simulate actual node clicks with physics
|
||||
const slideshowIntervalRef = useRef<NodeJS.Timeout | null>(null)
|
||||
const physicsTimeoutRef = useRef<NodeJS.Timeout | null>(null)
|
||||
const lastSelectedIndexRef = useRef<number>(-1)
|
||||
const isSlideshowActiveRef = useRef(isSlideshowActive)
|
||||
|
||||
|
|
@ -563,11 +564,15 @@ export const MemoryGraph = ({
|
|||
}, [nodes, handleNodeClick, centerViewportOn, containerSize, onSlideshowNodeChange, forceSimulation])
|
||||
|
||||
useEffect(() => {
|
||||
// Clear any existing interval when isSlideshowActive changes
|
||||
// Clear any existing interval and timeout when isSlideshowActive changes
|
||||
if (slideshowIntervalRef.current) {
|
||||
clearInterval(slideshowIntervalRef.current)
|
||||
slideshowIntervalRef.current = null
|
||||
}
|
||||
if (physicsTimeoutRef.current) {
|
||||
clearTimeout(physicsTimeoutRef.current)
|
||||
physicsTimeoutRef.current = null
|
||||
}
|
||||
|
||||
if (!isSlideshowActive) {
|
||||
// Close the popover when stopping slideshow
|
||||
|
|
@ -611,9 +616,13 @@ export const MemoryGraph = ({
|
|||
// Trigger physics animation briefly
|
||||
forceSimulationRef.current.reheat()
|
||||
|
||||
// Cool down physics after 1 second
|
||||
setTimeout(() => {
|
||||
// Cool down physics after 1 second (cleanup old timeout first)
|
||||
if (physicsTimeoutRef.current) {
|
||||
clearTimeout(physicsTimeoutRef.current)
|
||||
}
|
||||
physicsTimeoutRef.current = setTimeout(() => {
|
||||
forceSimulationRef.current.coolDown()
|
||||
physicsTimeoutRef.current = null
|
||||
}, 1000)
|
||||
|
||||
// Notify parent component
|
||||
|
|
@ -634,6 +643,10 @@ export const MemoryGraph = ({
|
|||
clearInterval(slideshowIntervalRef.current)
|
||||
slideshowIntervalRef.current = null
|
||||
}
|
||||
if (physicsTimeoutRef.current) {
|
||||
clearTimeout(physicsTimeoutRef.current)
|
||||
physicsTimeoutRef.current = null
|
||||
}
|
||||
}
|
||||
}, [isSlideshowActive]) // Only depend on isSlideshowActive
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue