Skip to content

Commit

Permalink
fix(Channel): remove auto play
Browse files Browse the repository at this point in the history
  • Loading branch information
Kechicode committed Jan 3, 2025
1 parent ce7335e commit f05b0c0
Showing 1 changed file with 28 additions and 29 deletions.
57 changes: 28 additions & 29 deletions src/views/Home/Channel/Page/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,13 @@ import classnames from 'classnames'
import useEmblaCarousel from 'embla-carousel-react'
import {
type MouseEvent,
useCallback,
// useCallback,
useEffect,
useRef,
useState,
} from 'react'

import { useCarousel } from '~/components/Hook/useCarousel'

// import { useCarousel } from '~/components/Hook/useCarousel'
import Dot from './Dot'
import styles from './styles.module.css'

Expand Down Expand Up @@ -61,22 +60,22 @@ const ChannelCarousel = () => {

// state of carusel
const scrolling = useRef(false)
const settled = useRef(true)
// const settled = useRef(true)

const autoplay = useCallback(() => {
if (!carouselApi) {
return
}
if (carouselApi.canScrollNext()) {
setDot(carouselApi.selectedScrollSnap())
carouselApi.scrollNext()
} else {
setDot(0)
carouselApi.scrollTo(0)
}
}, [carouselApi])
// const autoplay = useCallback(() => {
// if (!carouselApi) {
// return
// }
// if (carouselApi.canScrollNext()) {
// setDot(carouselApi.selectedScrollSnap())
// carouselApi.scrollNext()
// } else {
// setDot(0)
// carouselApi.scrollTo(0)
// }
// }, [carouselApi])

const { play, stop } = useCarousel(autoplay, 5000)
// const { play, stop } = useCarousel(autoplay, 5000)

const scroll = (index: number) => {
if (!carouselApi) {
Expand Down Expand Up @@ -111,20 +110,20 @@ const ChannelCarousel = () => {
setDot(0)
setSnaps(carouselApi.scrollSnapList())

carouselApi.on('pointerDown', stop)
// carouselApi.on('pointerDown', stop)
carouselApi.on('select', onSelect)
carouselApi.on('scroll', () => {
if (!scrolling.current && settled.current) {
scrolling.current = true
settled.current = false
}
})
carouselApi.on('settle', () => {
scrolling.current = false
settled.current = true
})
// carouselApi.on('scroll', () => {
// if (!scrolling.current && settled.current) {
// scrolling.current = true
// settled.current = false
// }
// })
// carouselApi.on('settle', () => {
// scrolling.current = false
// settled.current = true
// })

play()
// play()
}, [carouselApi])

const [hash, setHash] = useState('')
Expand Down

0 comments on commit f05b0c0

Please sign in to comment.