11import { PartInstanceId , PieceInstanceId , SegmentId } from '@sofie-automation/corelib/dist/dataModel/Ids'
2- import { PropsWithChildren , useRef , useState } from 'react'
3- import { dragContext , IDragContext } from './DragContext'
4- import { PieceUi } from '../SegmentContainer/withResolvedSegment'
5- import { doUserAction , UserAction } from '../../lib/clientUserAction'
6- import { MeteorCall } from '../../lib/meteorApi'
2+ import { PropsWithChildren , useCallback , useEffect , useRef , useState } from 'react'
3+ import { dragContext , IDragContext } from './DragContext.js '
4+ import { PieceUi } from '../SegmentContainer/withResolvedSegment.js '
5+ import { doUserAction , UserAction } from '../../lib/clientUserAction.js '
6+ import { MeteorCall } from '../../lib/meteorApi.js '
77import { TFunction } from 'i18next'
88import { UIParts } from '../Collections.js'
99import { Segments } from '../../collections/index.js'
1010import { literal } from '../../lib/tempLib.js'
1111import { DefaultUserOperationRetimePiece , DefaultUserOperationsTypes } from '@sofie-automation/blueprints-integration'
12+ import RundownViewEventBus , {
13+ RundownViewEvents ,
14+ EditModeEvent ,
15+ } from '@sofie-automation/meteor-lib/dist/triggers/RundownViewEventBus'
1216
1317const DRAG_TIMEOUT = 10000
1418
@@ -21,6 +25,8 @@ export function DragContextProvider({ t, children }: PropsWithChildren<Props>):
2125 const [ pieceId , setPieceId ] = useState < undefined | PieceInstanceId > ( undefined )
2226 const [ piece , setPiece ] = useState < undefined | PieceUi > ( undefined )
2327
28+ const [ enabled , setEnabled ] = useState ( false )
29+
2430 const partIdRef = useRef < undefined | PartInstanceId > ( undefined )
2531 const positionRef = useRef ( { x : 0 , y : 0 } )
2632 const segmentIdRef = useRef < undefined | SegmentId > ( undefined )
@@ -137,10 +143,27 @@ export function DragContextProvider({ t, children }: PropsWithChildren<Props>):
137143 positionRef . current = pos
138144 }
139145
146+ const onSetEditMode = useCallback ( ( e : EditModeEvent ) => {
147+ if ( e . state === 'toggle' ) {
148+ setEnabled ( ( s ) => ! s )
149+ } else {
150+ setEnabled ( e . state )
151+ }
152+ } , [ ] )
153+
154+ useEffect ( ( ) => {
155+ RundownViewEventBus . on ( RundownViewEvents . EDIT_MODE , onSetEditMode )
156+ return ( ) => {
157+ RundownViewEventBus . off ( RundownViewEvents . EDIT_MODE , onSetEditMode )
158+ }
159+ } )
160+
140161 const ctx = literal < IDragContext > ( {
141162 pieceId,
142163 piece,
143164
165+ enabled,
166+
144167 startDrag,
145168 setHoveredPart,
146169 } )
0 commit comments