@@ -23,6 +23,7 @@ import "./poster.scss";
2323function Poster ( { slide, content, run, slideDone, executionId } ) {
2424 const [ translations , setTranslations ] = useState ( { } ) ;
2525 const [ currentEvent , setCurrentEvent ] = useState ( null ) ;
26+ const [ currentIndex , setCurrentIndex ] = useState ( null ) ;
2627 const [ show , setShow ] = useState ( true ) ;
2728 const timerRef = useRef ( null ) ;
2829 const animationTimerRef = useRef ( null ) ;
@@ -88,7 +89,7 @@ function Poster({ slide, content, run, slideDone, executionId }) {
8889
8990 const formatDateNoYear = ( date ) => {
9091 if ( ! date ) return "" ;
91- return capitalize ( dayjs ( date ) . locale ( localeDa ) . format ( "DD MMMM " ) ) ;
92+ return capitalize ( dayjs ( date ) . locale ( localeDa ) . format ( "DD MMM " ) ) ;
9293 } ;
9394
9495 const getUrlDomain = ( urlString ) => {
@@ -101,37 +102,55 @@ function Poster({ slide, content, run, slideDone, executionId }) {
101102 ) ;
102103 } ;
103104
105+ useEffect ( ( ) => {
106+ if ( currentEvent ) {
107+ setShow ( true ) ;
108+ }
109+ } , [ currentEvent ] ) ;
110+
104111 // Setup feed entry switch and animation, if there is more than one post.
105112 useEffect ( ( ) => {
106- if ( ! currentEvent ) return ;
113+ if ( currentIndex === null ) {
114+ return ;
115+ }
107116
108- timerRef . current = setTimeout ( ( ) => {
109- const currentIndex = feedData . indexOf ( currentEvent ) ;
110- const nextIndex = ( currentIndex + 1 ) % feedData . length ;
117+ setCurrentEvent ( feedData [ currentIndex ] ) ;
118+
119+ const nextIndex = ( currentIndex + 1 ) % feedData . length ;
111120
121+ if ( nextIndex > 0 ) {
122+ if ( animationTimerRef ?. current ) {
123+ clearInterval ( animationTimerRef . current ) ;
124+ }
125+
126+ animationTimerRef . current = setTimeout ( ( ) => {
127+ setShow ( false ) ;
128+ } , entryDurationMilliseconds - animationDuration + 50 ) ;
129+ }
130+
131+ if ( timerRef ?. current ) {
132+ clearInterval ( timerRef . current ) ;
133+ }
134+
135+ timerRef . current = setTimeout ( ( ) => {
112136 if ( nextIndex === 0 ) {
113137 slideDone ( slide ) ;
114138 } else {
115- setCurrentEvent ( feedData [ nextIndex ] ) ;
116- setShow ( true ) ;
139+ setCurrentIndex ( nextIndex ) ;
117140 }
118141 } , entryDurationMilliseconds ) ;
119-
120- animationTimerRef . current = setTimeout ( ( ) => {
121- setShow ( false ) ;
122- } , entryDurationMilliseconds - animationDuration ) ;
123- } , [ currentEvent ] ) ;
142+ } , [ currentIndex ] ) ;
124143
125144 useEffect ( ( ) => {
126145 if ( run ) {
127146 if ( feedData && currentEvent === null && feedData ?. length > 0 ) {
128- const [ first ] = feedData ;
129- setCurrentEvent ( first ) ;
147+ setCurrentIndex ( 0 ) ;
130148 } else {
131149 setTimeout ( ( ) => slideDone ( slide ) , 1000 ) ;
132150 }
133151 } else {
134152 setCurrentEvent ( null ) ;
153+ setCurrentIndex ( null ) ;
135154 }
136155 } , [ run ] ) ;
137156
@@ -142,10 +161,10 @@ function Poster({ slide, content, run, slideDone, executionId }) {
142161 setTranslations ( da ) ;
143162
144163 return function cleanup ( ) {
145- if ( timerRef ?. current !== null ) {
164+ if ( timerRef ?. current ) {
146165 clearInterval ( timerRef . current ) ;
147166 }
148- if ( animationTimerRef ?. current !== null ) {
167+ if ( animationTimerRef ?. current ) {
149168 clearInterval ( animationTimerRef . current ) ;
150169 }
151170 } ;
@@ -159,12 +178,16 @@ function Poster({ slide, content, run, slideDone, executionId }) {
159178 < div className = { `template-poster ${ showLogo && "with-logo" } ` } >
160179 < div
161180 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- } }
181+ style = {
182+ image
183+ ? {
184+ backgroundImage : `url("${ image } ")` ,
185+ ...( show
186+ ? { animation : `fade-in ${ animationDuration } ms` }
187+ : { animation : `fade-out ${ animationDuration } ms` } ) ,
188+ }
189+ : { }
190+ }
168191 />
169192 < div className = "header-area" >
170193 < div className = "center" >
0 commit comments