Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

add autoplay feature to template caurosal #315

Merged
merged 1 commit into from
Dec 14, 2023
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
add autoplay feature to template caurosal
  • Loading branch information
unique011 committed Dec 13, 2023
commit 0c73a0b55238cb04c5f46642c834ec20b7e13c45
18 changes: 14 additions & 4 deletions src/pages/auth/HomePage.jsx
Original file line number Diff line number Diff line change
@@ -1,9 +1,8 @@
import React, { useContext } from "react";
import React, { useContext, useEffect, useState } from "react";
import { Carousel, Col, Container, Row } from "react-bootstrap";
import { Link } from "react-router-dom";
import { TemplateContext } from "../../context/TemplateContext";
import { Pattern3Default } from "../../components/common/CustomPatterns";

const HomePage = () => {
return (
<React.Fragment>
Expand Down Expand Up @@ -75,11 +74,22 @@ export default HomePage;

const TemplateCarousel = () => {
const [templates] = useContext(TemplateContext);
const [index, setIndex] = useState(0);

const handleSelect = (selectedIndex) => {
setIndex(selectedIndex);
};
useEffect(() => {
const interval = setInterval(() => {
setIndex((prevIndex) => (prevIndex + 1) % templates.length);
}, 5000);
return () => clearInterval(interval);
}, [index]);

return (
<Carousel>
<Carousel activeIndex={index} onSelect={handleSelect} interval={null}>
{templates.map((template, index) => (
<Carousel.Item interval={4000} key={index}>
<Carousel.Item key={index}>
<img className="d-block w-100" src={template.img} alt="...." />
<Carousel.Caption>
<h3 className="text-white">{template.title}</h3>
Expand Down