Skip to content

Commit

Permalink
fix: fix carousel not scrolling on first render
Browse files Browse the repository at this point in the history
  • Loading branch information
Jonath-z committed Dec 29, 2022
1 parent fb8db42 commit 8dc60b5
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 17 deletions.
8 changes: 2 additions & 6 deletions components/modules/FeaturedAlbum/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,12 +11,8 @@ const FeaturedAlbum = () => {
title="Featured Albums"
className="mt-8 p-4 rounded-lg shadow-lg mr-4 bg-white"
>
{data.map((song) => {
return (
<>
<FeaturedAlbumCard album={song} />
</>
);
{data.map((song, index) => {
return <FeaturedAlbumCard album={song} key={index} />;
})}
</Carousel>
);
Expand Down
6 changes: 2 additions & 4 deletions components/modules/__modules__/Carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,9 +23,7 @@ const Carousel: FC<CarouselProps> = ({
scrollContainer.current,
40,
200,
scrollContainer.current?.offsetWidth
? -scrollContainer.current?.offsetWidth
: 0
-(scrollContainer.current?.offsetWidth as number)
);
};

Expand All @@ -34,7 +32,7 @@ const Carousel: FC<CarouselProps> = ({
scrollContainer.current,
40,
200,
scrollContainer.current?.offsetWidth
scrollContainer.current?.offsetWidth as number
);
};
return (
Expand Down
10 changes: 4 additions & 6 deletions components/modules/hooks/useSideScroll.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,10 @@ const useSideScroll = () => {
let scrollAmount = 0;

const slideTimer = setInterval(() => {
if (element?.scrollLeft) {
element.scrollLeft += step;
scrollAmount += Math.abs(step);
if (scrollAmount >= distance) {
clearInterval(slideTimer);
}
element!.scrollLeft += step as number;
scrollAmount += Math.abs(step as number);
if (scrollAmount >= distance) {
clearInterval(slideTimer);
}
}, speed);
};
Expand Down
3 changes: 2 additions & 1 deletion tsconfig.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"components/modules/__modules__/_Vectors/wavePlayVector.jsx",
"components/modules/AddNewSinger/index.tsx",
"components/modules/utils/config/audioPlayer.tsx",
"components/modules/utils/config/audioControls.tsx"
"components/modules/utils/config/audioControls.tsx",
"components/modules/__modules__/Carousel/index.jsx"
],
"exclude": ["node_modules"]
}

0 comments on commit 8dc60b5

Please sign in to comment.