@@ -23,6 +23,7 @@ import "./poster.scss";
23
23
function Poster ( { slide, content, run, slideDone, executionId } ) {
24
24
const [ translations , setTranslations ] = useState ( { } ) ;
25
25
const [ currentEvent , setCurrentEvent ] = useState ( null ) ;
26
+ const [ currentIndex , setCurrentIndex ] = useState ( null ) ;
26
27
const [ show , setShow ] = useState ( true ) ;
27
28
const timerRef = useRef ( null ) ;
28
29
const animationTimerRef = useRef ( null ) ;
@@ -35,8 +36,7 @@ function Poster({ slide, content, run, slideDone, executionId }) {
35
36
36
37
// Animation.
37
38
const animationDuration = 500 ;
38
- const { entryDuration = 15 } = content ; // default 15s.
39
- const entryDurationMilliseconds = entryDuration * 1000 ;
39
+ const { duration = 15000 } = content ; // default 15s.
40
40
41
41
// Props from currentEvent.
42
42
const {
@@ -88,7 +88,7 @@ function Poster({ slide, content, run, slideDone, executionId }) {
88
88
89
89
const formatDateNoYear = ( date ) => {
90
90
if ( ! date ) return "" ;
91
- return capitalize ( dayjs ( date ) . locale ( localeDa ) . format ( "DD MMMM " ) ) ;
91
+ return capitalize ( dayjs ( date ) . locale ( localeDa ) . format ( "DD MMM " ) ) ;
92
92
} ;
93
93
94
94
const getUrlDomain = ( urlString ) => {
@@ -101,37 +101,55 @@ function Poster({ slide, content, run, slideDone, executionId }) {
101
101
) ;
102
102
} ;
103
103
104
+ useEffect ( ( ) => {
105
+ if ( currentEvent ) {
106
+ setShow ( true ) ;
107
+ }
108
+ } , [ currentEvent ] ) ;
109
+
104
110
// Setup feed entry switch and animation, if there is more than one post.
105
111
useEffect ( ( ) => {
106
- if ( ! currentEvent ) return ;
112
+ if ( currentIndex === null ) {
113
+ return ;
114
+ }
107
115
108
- timerRef . current = setTimeout ( ( ) => {
109
- const currentIndex = feedData . indexOf ( currentEvent ) ;
110
- const nextIndex = ( currentIndex + 1 ) % feedData . length ;
116
+ setCurrentEvent ( feedData [ currentIndex ] ) ;
117
+
118
+ const nextIndex = ( currentIndex + 1 ) % feedData . length ;
111
119
120
+ if ( nextIndex > 0 ) {
121
+ if ( animationTimerRef ?. current ) {
122
+ clearInterval ( animationTimerRef . current ) ;
123
+ }
124
+
125
+ animationTimerRef . current = setTimeout ( ( ) => {
126
+ setShow ( false ) ;
127
+ } , duration - animationDuration + 50 ) ;
128
+ }
129
+
130
+ if ( timerRef ?. current ) {
131
+ clearInterval ( timerRef . current ) ;
132
+ }
133
+
134
+ timerRef . current = setTimeout ( ( ) => {
112
135
if ( nextIndex === 0 ) {
113
136
slideDone ( slide ) ;
114
137
} else {
115
- setCurrentEvent ( feedData [ nextIndex ] ) ;
116
- setShow ( true ) ;
138
+ setCurrentIndex ( nextIndex ) ;
117
139
}
118
- } , entryDurationMilliseconds ) ;
119
-
120
- animationTimerRef . current = setTimeout ( ( ) => {
121
- setShow ( false ) ;
122
- } , entryDurationMilliseconds - animationDuration ) ;
123
- } , [ currentEvent ] ) ;
140
+ } , duration ) ;
141
+ } , [ currentIndex ] ) ;
124
142
125
143
useEffect ( ( ) => {
126
144
if ( run ) {
127
- if ( feedData && currentEvent === null && feedData ?. length > 0 ) {
128
- const [ first ] = feedData ;
129
- setCurrentEvent ( first ) ;
145
+ if ( feedData ?. length > 0 ) {
146
+ setCurrentIndex ( 0 ) ;
130
147
} else {
131
148
setTimeout ( ( ) => slideDone ( slide ) , 1000 ) ;
132
149
}
133
150
} else {
134
151
setCurrentEvent ( null ) ;
152
+ setCurrentIndex ( null ) ;
135
153
}
136
154
} , [ run ] ) ;
137
155
@@ -142,10 +160,10 @@ function Poster({ slide, content, run, slideDone, executionId }) {
142
160
setTranslations ( da ) ;
143
161
144
162
return function cleanup ( ) {
145
- if ( timerRef ?. current !== null ) {
163
+ if ( timerRef ?. current ) {
146
164
clearInterval ( timerRef . current ) ;
147
165
}
148
- if ( animationTimerRef ?. current !== null ) {
166
+ if ( animationTimerRef ?. current ) {
149
167
clearInterval ( animationTimerRef . current ) ;
150
168
}
151
169
} ;
@@ -159,12 +177,16 @@ function Poster({ slide, content, run, slideDone, executionId }) {
159
177
< div className = { `template-poster ${ showLogo && "with-logo" } ` } >
160
178
< div
161
179
className = { `image-area ${ mediaContain ? "media-contain" : "" } ` }
162
- style = { {
163
- backgroundImage : `url("${ image } ")` ,
164
- ...( show
165
- ? { animation : `fade-in ${ animationDuration } ms` }
166
- : { animation : `fade-out ${ animationDuration } ms` } ) ,
167
- } }
180
+ style = {
181
+ image
182
+ ? {
183
+ backgroundImage : `url("${ image } ")` ,
184
+ ...( show
185
+ ? { animation : `fade-in ${ animationDuration } ms` }
186
+ : { animation : `fade-out ${ animationDuration } ms` } ) ,
187
+ }
188
+ : { }
189
+ }
168
190
/>
169
191
< div className = "header-area" >
170
192
< div className = "center" >
@@ -292,7 +314,7 @@ Poster.propTypes = {
292
314
) ,
293
315
} ) . isRequired ,
294
316
content : PropTypes . shape ( {
295
- entryDuration : PropTypes . number ,
317
+ duration : PropTypes . number ,
296
318
showLogo : PropTypes . bool ,
297
319
mediaContain : PropTypes . bool ,
298
320
} ) . isRequired ,
0 commit comments