1- import { useCallback , useMemo } from 'react'
1+ import { useCallback , useEffect , useMemo , useRef } from 'react'
22import type { PartId } from '@sofie-automation/corelib/dist/dataModel/Ids'
33import type { AdLibAction } from '@sofie-automation/corelib/dist/dataModel/AdlibAction'
44import type { AdLibPiece } from '@sofie-automation/corelib/dist/dataModel/AdLibPiece'
@@ -20,6 +20,7 @@ interface IProps {
2020
2121export const LinePartAdLibIndicator : React . FC < IProps > = function LinePartAdLibIndicator ( { sourceLayers, partId } ) {
2222 const { t } = useTranslation ( )
23+ const revealTimeoutRef = useRef < ReturnType < typeof setTimeout > | undefined > ( undefined )
2324
2425 const sourceLayerIds = useMemo ( ( ) => sourceLayers . map ( ( sourceLayer ) => sourceLayer . _id ) , [ sourceLayers ] )
2526 const label = useMemo ( ( ) => sourceLayers [ 0 ] ?. name ?? '' , [ sourceLayers ] )
@@ -64,13 +65,22 @@ export const LinePartAdLibIndicator: React.FC<IProps> = function LinePartAdLibIn
6465 RundownViewEventBus . emit ( RundownViewEvents . SHELF_STATE , {
6566 state : true ,
6667 } )
67- setTimeout ( ( ) => {
68+ revealTimeoutRef . current = setTimeout ( ( ) => {
6869 RundownViewEventBus . emit ( RundownViewEvents . REVEAL_IN_SHELF , {
6970 pieceId : pieceId ,
7071 } )
7172 } , 100 )
7273 } , [ adLibPieces , adLibActions ] )
7374
75+ useEffect ( ( ) => {
76+ return ( ) => {
77+ if ( revealTimeoutRef . current ) {
78+ clearTimeout ( revealTimeoutRef . current )
79+ revealTimeoutRef . current = undefined
80+ }
81+ }
82+ } , [ ] )
83+
7484 return (
7585 < StudioContext . Consumer >
7686 { ( studio ) => {
0 commit comments