Skip to content

Commit

Permalink
feat(Channel): update
Browse files Browse the repository at this point in the history
  • Loading branch information
Kechicode committed Jan 3, 2025
1 parent 8c9868e commit 3f200fd
Showing 1 changed file with 38 additions and 25 deletions.
63 changes: 38 additions & 25 deletions src/views/Home/Channel/Page/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,9 @@ const ChannelCarousel = () => {

useNativeEventListener('resize', () => {
if (typeof window !== 'undefined') {
if (window.innerWidth < 453) {
setColumnCount('4')
}
if (window.innerWidth >= 453) {
setColumnCount('5')
}
Expand All @@ -183,16 +186,21 @@ const ChannelCarousel = () => {
}
})

const pageCount = Math.ceil(items.length / (Number(columnCount) * 2))
let slicedItems = []
for (let i = 0; i < pageCount; i++) {
slicedItems.push(
items.slice(
i * (Number(columnCount) * 2),
(i + 1) * (Number(columnCount) * 2)
const [slicedItems, setSlicedItems] = useState<any[]>([])

useEffect(() => {
const pageCount = Math.ceil(items.length / (Number(columnCount) * 2))
const _slicedItems: any[] = []
for (let i = 0; i < pageCount; i++) {
_slicedItems.push(
items.slice(
i * (Number(columnCount) * 2),
(i + 1) * (Number(columnCount) * 2)
)
)
)
}
}
setSlicedItems(_slicedItems)
}, [columnCount])

// state of carusel
const scrolling = useRef(false)
Expand Down Expand Up @@ -253,7 +261,7 @@ const ChannelCarousel = () => {
}
}, [])

const [selectedChannel, setSelectedChannel] = useState(0)
const [selectedChannel, setSelectedChannel] = useState(1)

useEffect(() => {
if (hash) {
Expand All @@ -274,21 +282,26 @@ const ChannelCarousel = () => {
return (
<div key={i} className={styles.slide}>
<div className={styles.content}>
{its?.map((item, i) => {
const title = item.title || ''
return (
<a
key={i}
href={item.link}
className={classnames({
[styles.selectedChannel]:
selectedChannel === parseInt(item.id, 10),
})}
>
{title}
</a>
)
})}
{its?.map(
(
item: { title: string; id: string; link: string },
index: number
) => {
const title = item.title || ''
return (
<a
key={index}
href={item.link || '#'}
className={classnames({
[styles.selectedChannel]:
selectedChannel === parseInt(item?.id || '1', 10),
})}
>
{title}
</a>
)
}
)}
</div>
</div>
)
Expand Down

0 comments on commit 3f200fd

Please sign in to comment.