Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 23 additions & 6 deletions components/carousel.js
Original file line number Diff line number Diff line change
Expand Up @@ -59,31 +59,48 @@ function Carousel ({ close, mediaArr, src, setOptions }) {
if (index === -1) return [src, false, false]
return [mediaArr[index][0], index > 0, index < mediaArr.length - 1]
}, [src, mediaArr, index])
const IDLE_DELAY = 2000
const [navActive, setNavActive] = useState(false)
const idleTimerRef = useRef()
const getIdleTimer = useCallback(() => {
if (idleTimerRef.current) clearTimeout(idleTimerRef.current)
idleTimerRef.current = setTimeout(() => setNavActive(false), IDLE_DELAY)
}, [])
const bumpActivity = useCallback(() => {
setNavActive(true)
getIdleTimer()
}, [getIdleTimer])

useEffect(() => {
if (index === -1) return
setOptions({
overflow: <CarouselOverflow {...mediaArr[index][1]} />
})
}, [index, mediaArr, setOptions])
bumpActivity()
return () => {
if (idleTimerRef.current) clearTimeout(idleTimerRef.current)
}
}, [index, mediaArr, setOptions, bumpActivity])

const moveLeft = useCallback(() => {
setIndex(i => Math.max(0, i - 1))
}, [setIndex])
bumpActivity()
}, [setIndex, bumpActivity])

const moveRight = useCallback(() => {
setIndex(i => Math.min(mediaArr.length - 1, i + 1))
}, [setIndex, mediaArr.length])
bumpActivity()
}, [setIndex, mediaArr.length, bumpActivity])

useSwiping({ moveLeft, moveRight })
useArrowKeys({ moveLeft, moveRight })

return (
<div className={styles.fullScreenContainer} onClick={close}>
<div className={styles.fullScreenContainer} onClick={close} onMouseMove={bumpActivity} onTouchStart={bumpActivity}>
<img className={styles.fullScreen} src={currentSrc} />
<div className={styles.fullScreenNavContainer}>
<div
className={classNames(styles.fullScreenNav, !canGoLeft && 'invisible', styles.left)}
className={classNames(styles.fullScreenNav, navActive ? styles.navActive : styles.navIdle, !canGoLeft && 'invisible', styles.left)}
onClick={(e) => {
e.stopPropagation()
moveLeft()
Expand All @@ -92,7 +109,7 @@ function Carousel ({ close, mediaArr, src, setOptions }) {
<ArrowLeft width={34} height={34} />
</div>
<div
className={classNames(styles.fullScreenNav, !canGoRight && 'invisible', styles.right)}
className={classNames(styles.fullScreenNav, navActive ? styles.navActive : styles.navIdle, !canGoRight && 'invisible', styles.right)}
onClick={(e) => {
e.stopPropagation()
moveRight()
Expand Down
20 changes: 15 additions & 5 deletions components/carousel.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -30,8 +30,16 @@ img.fullScreen {
height: 100%;
}

div.fullScreenNav:hover > svg {
background-color: rgba(0, 0, 0, .5);
div.fullScreenNav.navActive > svg {
background-color: rgba(0,0,0,0.60);
fill: rgba(255,255,255,0.95);
opacity: 1;
}

div.fullScreenNav.navIdle > svg {
background-color: rgba(0,0,0,0.28);
fill: rgba(255,255,255,0.75);
opacity: 0.85;
}

div.fullScreenNav {
Expand All @@ -41,6 +49,8 @@ div.fullScreenNav {
height: 72px;
display: flex;
align-items: center;
opacity: 0.75;
transition: opacity 0.2s;
}

div.fullScreenNav.left {
Expand All @@ -53,11 +63,11 @@ div.fullScreenNav.right {

div.fullScreenNav > svg {
border-radius: 50%;
backdrop-filter: blur(4px);
background-color: rgba(0, 0, 0, 0.7);
background-color: rgba(0, 0, 0, 0.25);
fill: white;
transition: background-color 0.2s, fill 0.2s;
max-height: 34px;
max-width: 34px;
padding: 0.35rem;
margin: .75rem;
}
}