-
Notifications
You must be signed in to change notification settings - Fork 1.2k
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
Fix partner slider animation in home page #5966
Open
Tharanishwaran
wants to merge
10
commits into
layer5io:master
Choose a base branch
from
Tharanishwaran:bugfix/academic-partners-slider-animation
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 6 commits
Commits
Show all changes
10 commits
Select commit
Hold shift + click to select a range
2632727
Fix partner slider animation in home page
Tharanishwaran 4af26ad
Merge branch 'master' into bugfix/academic-partners-slider-animation
Tharanishwaran 112035c
Merge branch 'master' into bugfix/academic-partners-slider-animation
Tharanishwaran 143f3e6
Merge branch 'master' into bugfix/academic-partners-slider-animation
Tharanishwaran c0d39ea
Merge branch 'master' into bugfix/academic-partners-slider-animation
Tharanishwaran 8aa0192
fix checks failing
Tharanishwaran 8f3574f
Merge branch 'layer5io:master' into bugfix/academic-partners-slider-a…
Tharanishwaran d6a0e6a
updated-Fix-partner-slider
Tharanishwaran fafaa6d
Update index.js
Tharanishwaran bcf164d
Merge branch 'master' into bugfix/academic-partners-slider-animation
vishalvivekm File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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"; | ||
|
@@ -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> | ||
|
@@ -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> | ||
)} | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we don't need to display a fallback as a message in our homepage this is not good. Do not add a fallback here. keep it as it was earlier and just fix smoothness of transitions |
||
</PartnerItemWrapper> | ||
); | ||
}; | ||
|
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why we using promise here? Will any one image anytime fail to load then all images will fail.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Promises seem to be ironically named. 😆