Skip to content

Instantly share code, notes, and snippets.

@mbritton
Created February 28, 2022 17:56
Show Gist options
  • Save mbritton/4ea7dbfddd1222dd661d288c30cd765a to your computer and use it in GitHub Desktop.
Save mbritton/4ea7dbfddd1222dd661d288c30cd765a to your computer and use it in GitHub Desktop.
const Slideshow = expiryTimeStamp => {
let [fileName, setFileName] = useState(SLIDESHOW_DATA.images[ 0 ].fileName);
const onExpire = () => {
(imageNum < SLIDESHOW_DATA.images.length && SLIDESHOW_DATA.images[ imageNum + 1 ] !== undefined) ?
imageNum++
: imageNum = 0;
fileName = SLIDESHOW_DATA.images[ imageNum ].fileName;
glowColor = SLIDESHOW_DATA.images[ imageNum ].color;
startSlideshow();
};
const startSlideshow = () => {
let time = new Date();
time.setSeconds(time.getSeconds() + SLIDESHOW_DATA.images[ imageNum ].time);
setTimeout(() => {
restart(time, true);
}, 0);
};
const toggle = () => {
isRunning ? pause() : resume();
};
const {
isRunning,
pause,
resume,
restart,
} = useTimer({ expiryTimeStamp, onExpire: onExpire, autoStart: true });
useEffect(() => {
startSlideshow();
return function cleanup() {
expiryTimeStamp = new Date();
imageNum = 0;
};
}, []);
return (
<div>
<div className={ 'slideshow-inner-wrapper' } onClick={ toggle }
style={ { backgroundImage: `url(${ fileName })`, boxShadow: `0px 0px 45px ${ glowColor }` } }></div>
</div>
);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment