1- import * as React from 'react'
1+ import React , { memo , useEffect } from 'react'
22import _ from 'underscore'
33import ClassNames from 'classnames'
44import {
77 RundownLayoutMiniRundown ,
88} from '@sofie-automation/meteor-lib/dist/collections/RundownLayouts'
99import { RundownLayoutsAPI } from '../../lib/rundownLayouts.js'
10- import { withTracker } from '../../lib/ReactMeteorData/ReactMeteorData.js'
10+ import { useTracker } from '../../lib/ReactMeteorData/ReactMeteorData.js'
1111import { DBRundownPlaylist } from '@sofie-automation/corelib/dist/dataModel/RundownPlaylist'
1212import { PartInstance } from '@sofie-automation/meteor-lib/dist/collections/PartInstances'
1313import { DBSegment } from '@sofie-automation/corelib/dist/dataModel/Segment'
@@ -18,77 +18,80 @@ import { UIPartInstances } from '../Collections.js'
1818import { RundownPlaylistClientUtil } from '../../lib/rundownPlaylistUtil.js'
1919
2020interface IMiniRundownPanelProps {
21- key : string
2221 visible ?: boolean
2322 layout : RundownLayoutBase
2423 panel : RundownLayoutMiniRundown
2524 playlist : DBRundownPlaylist
2625}
2726
28- interface IMiniRundownPanelTrackedProps {
29- currentPartInstance ?: PartInstance
30- nextPartInstance ?: PartInstance
31- allSegments ?: DBSegment [ ]
32- }
33-
34- interface IState { }
35-
3627interface MiniRundownSegment {
3728 identifier : string
3829 segmentName : string
3930 cssClass : string
4031}
4132
42- export class MiniRundownPanelInner extends React . Component < IMiniRundownPanelProps & IMiniRundownPanelTrackedProps > {
43- static currentSegmentCssClass = 'current-segment'
44- static nextSegmentCssClass = 'next-segment'
45- static panelContainerId = 'mini-rundown-panel__container'
46- static nextSegmentId = 'mini-rundown__next-segment'
47- static currentSegmentId = 'mini-rundown__current-segment'
33+ const MiniRundownPanelClassesAndIds = {
34+ currentSegmentCssClass : 'current-segment' ,
35+ nextSegmentCssClass : 'next-segment' ,
36+ panelContainerId : 'mini-rundown-panel__container' ,
37+ nextSegmentId : 'mini-rundown__next-segment' ,
38+ currentSegmentId : 'mini-rundown__current-segment' ,
39+ }
4840
49- componentDidMount ( ) : void {
50- this . scrollIntoView ( )
51- }
41+ export const MiniRundownPanel = memo (
42+ function MiniRundownPanelInner2 ( props : IMiniRundownPanelProps ) {
43+ // Trigger on mount, or when any props change
44+ useEffect ( ( ) => {
45+ Meteor . setTimeout ( ( ) => {
46+ const container = document . getElementById ( MiniRundownPanelClassesAndIds . panelContainerId )
47+ if ( ! container ) return
48+ const nextElement = document . getElementById ( MiniRundownPanelClassesAndIds . nextSegmentId )
49+ const currentElement = document . getElementById ( MiniRundownPanelClassesAndIds . currentSegmentId )
50+ if ( nextElement ) {
51+ container . scrollTop = nextElement . offsetTop - nextElement . clientHeight
52+ } else if ( currentElement ) {
53+ container . scrollTop = currentElement . offsetTop
54+ }
55+ } , 500 )
56+ } , [ ...Object . values < any > ( props ) ] )
5257
53- componentDidUpdate ( ) : void {
54- this . scrollIntoView ( )
55- }
56-
57- private scrollIntoView ( ) {
58- Meteor . setTimeout ( ( ) => {
59- const container = document . getElementById ( MiniRundownPanelInner . panelContainerId )
60- if ( ! container ) return
61- const nextElement = document . getElementById ( MiniRundownPanelInner . nextSegmentId )
62- const currentElement = document . getElementById ( MiniRundownPanelInner . currentSegmentId )
63- if ( nextElement ) {
64- container . scrollTop = nextElement . offsetTop - nextElement . clientHeight
65- } else if ( currentElement ) {
66- container . scrollTop = currentElement . offsetTop
67- }
68- } , 500 )
69- }
58+ const currentPartInstanceId : PartInstanceId | undefined = props . playlist . currentPartInfo ?. partInstanceId
59+ const currentPartInstance = useTracker (
60+ ( ) => currentPartInstanceId && UIPartInstances . findOne ( currentPartInstanceId ) ,
61+ [ currentPartInstanceId ]
62+ )
7063
71- render ( ) : JSX . Element {
72- const isDashboardLayout = RundownLayoutsAPI . isDashboardLayout ( this . props . layout )
73- const style = getElementStyle ( this . props , isDashboardLayout )
64+ const nextPartInstanceId : PartInstanceId | undefined = props . playlist . nextPartInfo ?. partInstanceId
65+ const nextPartInstance = useTracker (
66+ ( ) => nextPartInstanceId && UIPartInstances . findOne ( nextPartInstanceId ) ,
67+ [ nextPartInstanceId ]
68+ )
7469
75- const miniRundowns : MiniRundownSegment [ ] = getMiniRundownList (
76- this . props . allSegments ,
77- this . props . currentPartInstance ,
78- this . props . nextPartInstance
70+ const allSegments : DBSegment [ ] = useTracker (
71+ ( ) => RundownPlaylistClientUtil . getSegments ( props . playlist ) ,
72+ [ props . playlist . _id , props . playlist . rundownIdsInOrder ] ,
73+ [ ]
7974 )
8075
76+ const isDashboardLayout = RundownLayoutsAPI . isDashboardLayout ( props . layout )
77+ const style = getElementStyle ( props , isDashboardLayout )
78+
79+ const miniRundowns : MiniRundownSegment [ ] = getMiniRundownList ( allSegments , currentPartInstance , nextPartInstance )
80+
8181 return (
8282 < div
8383 key = { 'miniRundownContainer' }
84- className = { ClassNames ( 'dashboard-panel mini-rundown-panel' , getContainerClass ( this . props , isDashboardLayout ) ) }
85- style = { getContainerStyle ( this . props , isDashboardLayout ) }
84+ className = { ClassNames ( 'dashboard-panel mini-rundown-panel' , getContainerClass ( props , isDashboardLayout ) ) }
85+ style = { getContainerStyle ( props , isDashboardLayout ) }
8686 >
8787 < span className = "mini-rundown-panel__name" style = { style } key = { 'miniRundownHeader' } >
88- { this . props . panel . name } { ' ' }
88+ { props . panel . name } { ' ' }
8989 </ span >
9090
91- < div className = { MiniRundownPanelInner . panelContainerId } id = { MiniRundownPanelInner . panelContainerId } >
91+ < div
92+ className = { MiniRundownPanelClassesAndIds . panelContainerId }
93+ id = { MiniRundownPanelClassesAndIds . panelContainerId }
94+ >
9295 { miniRundowns . map ( ( miniRundown : MiniRundownSegment , index : number ) => (
9396 < div
9497 className = { miniRundown . cssClass }
@@ -113,31 +116,9 @@ export class MiniRundownPanelInner extends React.Component<IMiniRundownPanelProp
113116 </ div >
114117 </ div >
115118 )
116- }
117- }
118-
119- export const MiniRundownPanel = withTracker < IMiniRundownPanelProps , IState , IMiniRundownPanelTrackedProps > (
120- ( props : IMiniRundownPanelProps & IMiniRundownPanelTrackedProps ) => {
121- let currentPartInstance : PartInstance | undefined = undefined
122- let nextPartInstance : PartInstance | undefined = undefined
123-
124- const currentPartInstanceId : PartInstanceId | undefined = props . playlist . currentPartInfo ?. partInstanceId
125- if ( currentPartInstanceId ) {
126- currentPartInstance = UIPartInstances . findOne ( currentPartInstanceId )
127- }
128-
129- if ( props . playlist . nextPartInfo ) {
130- nextPartInstance = UIPartInstances . findOne ( props . playlist . nextPartInfo . partInstanceId )
131- }
132-
133- const allSegments : DBSegment [ ] = RundownPlaylistClientUtil . getSegments ( props . playlist )
134-
135- return { currentPartInstance, nextPartInstance, allSegments }
136119 } ,
137- ( _data , props : IMiniRundownPanelProps , nextProps : IMiniRundownPanelProps ) => {
138- return ! _ . isEqual ( props , nextProps )
139- }
140- ) ( MiniRundownPanelInner )
120+ ( prevProps , nextProps ) => _ . isEqual ( prevProps , nextProps )
121+ )
141122
142123function getMiniRundownList (
143124 allSegments ?: DBSegment [ ] ,
@@ -160,11 +141,11 @@ function getMiniRundownList(
160141
161142function getSegmentCssClass ( segment : DBSegment , currentPart ?: PartInstance , nextPart ?: PartInstance ) : string {
162143 if ( segment . _id === currentPart ?. segmentId ) {
163- return MiniRundownPanelInner . currentSegmentCssClass
144+ return MiniRundownPanelClassesAndIds . currentSegmentCssClass
164145 }
165146
166147 if ( segment . _id === nextPart ?. segmentId ) {
167- return MiniRundownPanelInner . nextSegmentCssClass
148+ return MiniRundownPanelClassesAndIds . nextSegmentCssClass
168149 }
169150
170151 return ''
@@ -200,10 +181,10 @@ function getElementKey(prefix: string, identifier: string, index: number): strin
200181
201182function getIdAttributeForNextSegment ( cssClass : string ) {
202183 switch ( cssClass ) {
203- case MiniRundownPanelInner . nextSegmentCssClass :
204- return { id : MiniRundownPanelInner . nextSegmentId }
205- case MiniRundownPanelInner . currentSegmentCssClass :
206- return { id : MiniRundownPanelInner . currentSegmentId }
184+ case MiniRundownPanelClassesAndIds . nextSegmentCssClass :
185+ return { id : MiniRundownPanelClassesAndIds . nextSegmentId }
186+ case MiniRundownPanelClassesAndIds . currentSegmentCssClass :
187+ return { id : MiniRundownPanelClassesAndIds . currentSegmentId }
207188 default :
208189 return { }
209190 }
0 commit comments