Carousal bug fixed (#464)

* added whats new feature

* added Changes log feature in whats new modal

* small fix

* samll fixe

* fixed parsing error issue and carousal dots issue

* excluded node_modules from parsing in webpack

* add support for video and make change log data optional

* carousal bug fix

* change setTimeout to 200ms
This commit is contained in:
Shailesh Parmar 2021-09-13 10:40:03 +05:30 committed by GitHub
parent b7adb5dc6b
commit 229795514e
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -21,17 +21,19 @@ import { uniqueId } from 'lodash';
import React, { useEffect, useRef, useState } from 'react'; import React, { useEffect, useRef, useState } from 'react';
import Slider from 'react-slick'; import Slider from 'react-slick';
type Props = { type CarousalData = {
data: {
title: string; title: string;
description: string; description: string;
isImage: boolean; isImage: boolean;
path: string; path: string;
}[]; };
type Props = {
data: CarousalData[];
}; };
const FeaturesCarousel = ({ data }: Props) => { const FeaturesCarousel = ({ data }: Props) => {
const [currentSlide, setCurrentSlide] = useState(0); const [isDataChange, setIsDataChange] = useState(false);
const sliderRef = useRef<typeof Slider | null>(null); const sliderRef = useRef<typeof Slider | null>(null);
const settings = { const settings = {
@ -41,19 +43,27 @@ const FeaturesCarousel = ({ data }: Props) => {
speed: 500, speed: 500,
slidesToShow: 1, slidesToShow: 1,
slidesToScroll: 1, slidesToScroll: 1,
initialSlide: 0, beforeChange: (current: number) => {
afterChange: (currentSlide: number) => setCurrentSlide(currentSlide), if (current >= data.length) {
setIsDataChange(true);
} else {
setIsDataChange(false);
}
},
onReInit: () => {
if (isDataChange) {
setTimeout(() => {
sliderRef?.current?.slickGoTo(0);
}, 200);
}
},
}; };
useEffect(() => { useEffect(() => {
if (currentSlide > 0 && sliderRef.current) { setIsDataChange(true);
sliderRef.current.slickGoTo(0, true);
setCurrentSlide(0);
}
}, [data]); }, [data]);
return ( return (
<>
<Slider ref={sliderRef} {...settings}> <Slider ref={sliderRef} {...settings}>
{data.map((d) => ( {data.map((d) => (
<div className="tw-px-1" key={uniqueId()}> <div className="tw-px-1" key={uniqueId()}>
@ -75,7 +85,6 @@ const FeaturesCarousel = ({ data }: Props) => {
</div> </div>
))} ))}
</Slider> </Slider>
</>
); );
}; };