Skip to content

Commit

Permalink
Fix media position
Browse files Browse the repository at this point in the history
  • Loading branch information
barbara-chaves committed Dec 4, 2024
1 parent 3001c48 commit f11178e
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions client/src/components/ui/carousel/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -188,20 +188,19 @@ type PropType = PropsWithChildren & {
};

const EmblaCarousel: React.FC<PropType> = ({ options, medias, selected }) => {
const [emblaRef, emblaApi] = useEmblaCarousel(options);
const [emblaRef, emblaApi] = useEmblaCarousel({
loop: true,
startIndex: selected,
align: 'center',
inViewThreshold: 0.5,
...options,
});
const { selectedIndex, scrollSnaps, onDotButtonClick } = useDotButton(emblaApi);
// const { prevBtnDisabled, nextBtnDisabled, onPrevButtonClick, onNextButtonClick } =
// usePrevNextButtons(emblaApi);

const [currSlider, setCurrSlider] = useState(0);

useEffect(() => {
if (selected !== undefined && emblaApi) {
emblaApi.scrollTo(selected);
setCurrSlider(selected);
}
}, [selected, emblaApi]);

const handleSelectedSlide = useCallback((embla: EmblaCarouselType) => {
setCurrSlider(embla.selectedScrollSnap());
}, []);
Expand All @@ -223,7 +222,9 @@ const EmblaCarousel: React.FC<PropType> = ({ options, medias, selected }) => {
<div
className={cn(
'embla__slide flex-[0_0_60%] pl-4 sm:pl-10',
index === currSlider ? 'h-[80vh]' : 'h-[40vh]'
index === currSlider ? 'h-[80vh]' : 'h-[40vh]',
medias.length === 2 && index === 0 && 'ml-[20%]',
medias.length === 2 && index === 1 && 'mr-[20%]'
)}
key={index}
>
Expand Down

0 comments on commit f11178e

Please sign in to comment.