Skip to content

Commit

Permalink
Fix layer5io#5805: Remove loading message to improve animation in Aca…
Browse files Browse the repository at this point in the history
…demic Partners slider

Signed-off-by: Tharanishwaran <[email protected]>
  • Loading branch information
Tharanishwaran committed Oct 2, 2024
1 parent 8489c16 commit bd429e8
Showing 1 changed file with 61 additions and 29 deletions.
90 changes: 61 additions & 29 deletions src/sections/Home/Partners-home/index.js
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React from "react";
import React, { useState, useEffect } from "react";
import { Container, Row } from "../../../reusecore/Layout";
import SectionTitle from "../../../reusecore/SectionTitle";
import PartnerItemWrapper from "./partnerSection.style";
Expand All @@ -8,27 +8,57 @@ import Slider from "react-slick";
import "slick-carousel/slick/slick.css";
import "slick-carousel/slick/slick-theme.css";

const settings = {
initialSlide: 1,
lazyLoad: true,
arrows: false,
dots: false,
infinite: true,
speed: 500,
centerMode: true,
variableWidth: true,
autoplay: true,
autoplaySpeed: 1500,
className: "partner-slider",
responsive: [
{
breakpoint: 1400,
settings: "unslick"
}
]
};
const PartnerImage = ({ partner }) => (
<div className={partner.innerDivStyle}>
<img
className="partner-image"
id={partner.name}
src={partner.imageLink}
alt={partner.name}
width={partner.imageWidth}
height={partner.imageHeight}
/>
</div>
);

const Projects = () => {
const [imagesLoaded, setImagesLoaded] = useState(false);

useEffect(() => {
const imagePromises = partners.map(partner => {
return new Promise((resolve, reject) => {
const img = new Image();
img.onload = resolve;
img.onerror = reject;
img.src = partner.imageLink;
});
});

Promise.all(imagePromises)
.then(() => setImagesLoaded(true))
.catch(error => console.error("Error preloading images:", error));
}, []);

const settings = {
initialSlide: 1,
lazyLoad: false,
arrows: false,
dots: false,
infinite: true,
speed: 500,
centerMode: true,
variableWidth: true,
autoplay: true,
autoplaySpeed: 1500,
className: "partner-slider",
responsive: [
{
breakpoint: 1400,
settings: "unslick"
}
]
};

return (
<PartnerItemWrapper>
<Container>
Expand All @@ -42,15 +72,17 @@ const Projects = () => {
</SectionTitle>
</Row>
</Container>
<Slider {...settings}>
{partners.map((partner, index) => (
<Link className="partner-card" to={partner.imageRoute} key={index}>
<div className={partner.innerDivStyle}>
<img className="partner-image" id={partner.name} loading="lazy" src={partner.imageLink} alt={partner.name} width={partner.imageWidth} height={partner.imageHeight} />
</div>
</Link>
))}
</Slider>
{imagesLoaded ? (
<Slider {...settings}>
{partners.map((partner, index) => (
<Link className="partner-card" to={partner.imageRoute} key={index}>
<PartnerImage partner={partner} />
</Link>
))}
</Slider>
) : (
<div style={{ textAlign: 'center', padding: '20px' }}>Loading partners...</div>
)}
</PartnerItemWrapper>
);
};
Expand Down

0 comments on commit bd429e8

Please sign in to comment.