Do not indicate topic update on selection
This commit is contained in:
@@ -1,15 +1,17 @@
|
|||||||
import React, { useEffect } from 'react'
|
import React, { useEffect } from 'react'
|
||||||
var inViewport = require('in-viewport')
|
const inViewport = require('in-viewport')
|
||||||
|
|
||||||
export function useAnimationToIndicateTopicUpdate(
|
export function useAnimationToIndicateTopicUpdate(
|
||||||
ref: React.MutableRefObject<HTMLDivElement | undefined>,
|
ref: React.MutableRefObject<HTMLDivElement | undefined>,
|
||||||
lastUpdate: number,
|
lastUpdate: number,
|
||||||
className: string,
|
className: string,
|
||||||
selected: boolean,
|
selected: boolean,
|
||||||
|
selectionLastUpdate: number,
|
||||||
shouldAnimate: boolean
|
shouldAnimate: boolean
|
||||||
) {
|
) {
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
if (ref.current && shouldAnimate && Date.now() - lastUpdate < 3000 && !selected) {
|
const selectionDidChange = Date.now() - selectionLastUpdate < 500
|
||||||
|
if (ref.current && shouldAnimate && Date.now() - lastUpdate < 3000 && !selected && !selectionDidChange) {
|
||||||
if (!inViewport(ref.current)) {
|
if (!inViewport(ref.current)) {
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
@@ -32,5 +34,5 @@ export function useAnimationToIndicateTopicUpdate(
|
|||||||
animationFrame && cancelAnimationFrame(animationFrame)
|
animationFrame && cancelAnimationFrame(animationFrame)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}, [lastUpdate, selected, shouldAnimate, className])
|
}, [lastUpdate, selected, selectionLastUpdate, shouldAnimate, className])
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -0,0 +1,14 @@
|
|||||||
|
import { useCallback, useState } from 'react'
|
||||||
|
|
||||||
|
interface SelectedState {
|
||||||
|
selected: boolean
|
||||||
|
lastUpdate: number
|
||||||
|
}
|
||||||
|
|
||||||
|
export function useSelectionState(initialSelectionState: boolean): [boolean, number, (selected: boolean) => void] {
|
||||||
|
const [state, setState] = useState<SelectedState>({ selected: initialSelectionState, lastUpdate: 0 })
|
||||||
|
const setSelected = useCallback((selected: boolean) => {
|
||||||
|
setState({ selected, lastUpdate: Date.now() })
|
||||||
|
}, [])
|
||||||
|
return [state.selected, state.lastUpdate, setSelected]
|
||||||
|
}
|
||||||
@@ -11,6 +11,7 @@ import { useAnimationToIndicateTopicUpdate } from './effects/useAnimationToIndic
|
|||||||
import { useDeleteKeyCallback } from './effects/useDeleteKeyCallback'
|
import { useDeleteKeyCallback } from './effects/useDeleteKeyCallback'
|
||||||
import { useIsAllowedToAutoExpandState } from './effects/useIsAllowedToAutoExpandState'
|
import { useIsAllowedToAutoExpandState } from './effects/useIsAllowedToAutoExpandState'
|
||||||
import { useViewModelSubscriptions } from './effects/useViewModelSubscriptions'
|
import { useViewModelSubscriptions } from './effects/useViewModelSubscriptions'
|
||||||
|
import { useSelectionState } from './useSelectionState'
|
||||||
|
|
||||||
export interface Props {
|
export interface Props {
|
||||||
isRoot?: boolean
|
isRoot?: boolean
|
||||||
@@ -29,7 +30,7 @@ export interface Props {
|
|||||||
function TreeNodeComponent(props: Props) {
|
function TreeNodeComponent(props: Props) {
|
||||||
const { actions, classes, className, settings, theme, treeNode, lastUpdate, name } = props
|
const { actions, classes, className, settings, theme, treeNode, lastUpdate, name } = props
|
||||||
const [collapsedOverride, setCollapsedOverride] = useState<boolean | undefined>(undefined)
|
const [collapsedOverride, setCollapsedOverride] = useState<boolean | undefined>(undefined)
|
||||||
const [selected, setSelected] = useState(false)
|
const [selected, selectionLastUpdate, setSelected] = useSelectionState(false)
|
||||||
const nodeRef = useRef<HTMLDivElement>()
|
const nodeRef = useRef<HTMLDivElement>()
|
||||||
const isAllowedToAutoExpand = useIsAllowedToAutoExpandState(props)
|
const isAllowedToAutoExpand = useIsAllowedToAutoExpandState(props)
|
||||||
const deleteTopicCallback = useDeleteKeyCallback(treeNode, actions)
|
const deleteTopicCallback = useDeleteKeyCallback(treeNode, actions)
|
||||||
@@ -42,6 +43,7 @@ function TreeNodeComponent(props: Props) {
|
|||||||
lastUpdate,
|
lastUpdate,
|
||||||
animationClass,
|
animationClass,
|
||||||
selected,
|
selected,
|
||||||
|
selectionLastUpdate,
|
||||||
settings.get('highlightTopicUpdates')
|
settings.get('highlightTopicUpdates')
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user