1- import React , { useRef , useState } from 'react'
1+ import React , { useContext , useRef , useState } from 'react'
22import { ISourceLayer } from '@sofie-automation/blueprints-integration'
33import { PieceExtended } from '../../../lib/RundownResolver'
44import { getElementDocumentOffset , OffsetPosition } from '../../../utils/positions'
@@ -7,6 +7,13 @@ import { ThumbnailRenderer } from './Renderers/ThumbnailRendererFactory'
77import { PieceElement } from '../../SegmentContainer/PieceElement'
88import { UIStudio } from '@sofie-automation/meteor-lib/dist/api/studios'
99import { PartId , PartInstanceId } from '@sofie-automation/corelib/dist/dataModel/Ids'
10+ import { useContentStatusForPieceInstance } from '../../SegmentTimeline/withMediaObjectStatus'
11+ import {
12+ convertPreviewToContents ,
13+ convertSourceLayerItemToPreview ,
14+ IPreviewPopUpSession ,
15+ PreviewPopUpContext ,
16+ } from '../../PreviewPopUp/PreviewPopUpContext'
1017
1118interface IProps {
1219 partId : PartId
@@ -40,11 +47,21 @@ export function StoryboardPartThumbnailInner({
4047 const [ mousePosition , setMousePosition ] = useState ( 0 )
4148 const thumbnailEl = useRef < HTMLDivElement > ( null )
4249
50+ const previewContext = useContext ( PreviewPopUpContext )
51+ const previewSession = useRef < IPreviewPopUpSession | null > ( null )
52+
53+ const contentStatus = useContentStatusForPieceInstance ( piece . instance )
54+ const previewContents = piece . instance . piece . content . popUpPreview
55+ ? convertPreviewToContents ( piece . instance . piece . content . popUpPreview , contentStatus )
56+ : layer
57+ ? convertSourceLayerItemToPreview ( layer . type , piece , contentStatus )
58+ : [ ]
59+
4360 const onPointerEnter = ( e : React . PointerEvent < HTMLDivElement > ) => {
4461 if ( e . pointerType !== 'mouse' ) {
4562 return
4663 }
47- setHover ( true )
64+ // setHover(true)
4865
4966 const newOffset = thumbnailEl . current && getElementDocumentOffset ( thumbnailEl . current )
5067 if ( newOffset !== null ) {
@@ -58,13 +75,24 @@ export function StoryboardPartThumbnailInner({
5875 if ( newHeight !== null ) {
5976 setHeight ( newHeight )
6077 }
78+
79+ if ( previewContents . length > 0 )
80+ previewSession . current = previewContext . requestPreview ( e . target as any , previewContents , {
81+ time : mousePosition * ( piece . instance . piece . content . sourceDuration || 0 ) ,
82+ startCoordinate : e . screenX ,
83+ } )
6184 }
6285
6386 const onPointerLeave = ( e : React . PointerEvent < HTMLDivElement > ) => {
6487 if ( e . pointerType !== 'mouse' ) {
6588 return
6689 }
6790 setHover ( false )
91+
92+ if ( previewSession . current ) {
93+ previewSession . current . close ( )
94+ previewSession . current = null
95+ }
6896 }
6997
7098 const onPointerMove = ( e : React . PointerEvent < HTMLDivElement > ) => {
@@ -73,6 +101,9 @@ export function StoryboardPartThumbnailInner({
73101 }
74102 const newMousePosition = Math . max ( 0 , Math . min ( 1 , ( e . pageX - origin . left - 5 ) / ( width - 10 ) ) )
75103 setMousePosition ( newMousePosition )
104+ previewSession . current ?. setPointerTime (
105+ mousePosition * ( piece . instance . piece . content . sourceDuration ?? contentStatus ?. contentDuration ?? 0 )
106+ )
76107 }
77108
78109 return (
0 commit comments