Skip to content

Fixed popular section cards #710

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

Merged
merged 2 commits into from
Aug 9, 2024
Merged
Show file tree
Hide file tree
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
151 changes: 5 additions & 146 deletions src/Components/CardMain.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,3 @@
import React, { useState, useEffect, useRef } from "react";
import { BsFillHeartFill } from "react-icons/bs";
import { Link } from "react-router-dom";
import Card1 from "../img/card1.jpg";
import Card2 from "../img/card2.jpg";
import Card3 from "../img/card3.jpg";
Expand All @@ -15,6 +12,7 @@ import Card11 from "./projects/card11.png";
import Card12 from "./projects/card12.png";
import icon from './projects/profile.png';
import icon1 from './projects/profile1.png'
import Cardcontainer from "./Cardcontainer";


const features = [
Expand Down Expand Up @@ -164,150 +162,11 @@ const features = [
},
];

function CardMain({sortProjects}) {
const [isVisible, setIsVisible] = useState(
new Array(features.length).fill(false)
);
const containerRef = useRef(null);
let hideTimeout;
function CardMain() {
return(
<Cardcontainer features={features}/>
)

useEffect(() => {
return () => {
clearTimeout(hideTimeout);
};
}, []);

const handleMouseOver = (index) => {
clearTimeout(hideTimeout);
setIsVisible((prevIsVisible) => {
const newIsVisible = [...prevIsVisible];
newIsVisible[index] = true;
return newIsVisible;
});
};

const handleMouseOut = (index) => {
hideTimeout = setTimeout(() => {
setIsVisible((prevIsVisible) => {
const newIsVisible = [...prevIsVisible];
newIsVisible[index] = false;
return newIsVisible;
});
}, 200);
};

const scrollToTop = () => {
if (containerRef.current) {
containerRef.current.scrollTo({
top: 0,
behavior: "smooth",
});
}

window.scrollTo({
top: 0,
behavior: "smooth",
});
};

const sortedProjects = sortProjects([...features]);

return (
<div
className="card"
ref={containerRef}
style={{ overflowY: "auto", maxHeight: "100vh" }}
>
{sortedProjects.map((project, index) => (
<div className="card_main" key={index}>
<img
src={project.img}
alt=""
className="card_main_img"
title={project.title}
/>
<div className="card_main_name">
<h2>{project.title}</h2>
<div className="card_main_icon" style={{ marginTop: '-18px' }}>
<i>
<BsFillHeartFill /> <span>{project.hearts}</span>
</i>
</div>
</div>
<div className="stat">
<div>
<p>
Developer<span>X</span>
</p>
</div>
<div>
<p>
Type of Project<span>{project.type}</span>
</p>
</div>
</div>
<div className="author" style={{ marginTop: '-12px' }}>
<div className="nameAuthor">
<p>By : &nbsp; </p>
<p
id="author_name"
onMouseOver={() => handleMouseOver(index)}
onMouseOut={() => handleMouseOut(index)}
>
{project.dev}
</p>
</div>
</div>
<div className="card_main_button" style={{ marginTop: '-16px' }}>
<Link to={`/readmore/${project.id}`} className="button btn">
Read More
</Link>
<a href="#" className="button2 btn">
Source Code
</a>
</div>

<div
className={`contBox ${isVisible[index] ? "visible" : "hidden"}`}
onMouseOver={() => handleMouseOver(index)}
onMouseOut={() => handleMouseOut(index)}
>
<div className="heading">
<img width={40} src={project.pro} alt=""/>
<div className="details1">
<p id="name">@{project.dev}</p>
<p id="occupation">{project.role}</p>
</div>
</div>
<div className="details2">
<p id="info">{project.about}</p>
</div>
<div className="btnnn">
<button>Follow Me</button>
<button>
<Link to={`/profile/${project.id}`}>View Profile</Link>
</button>
</div>
</div>
</div>
))}

<div
style={{
textAlign: "center",
padding: "20px",
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "100%",
}}
>
<button onClick={scrollToTop} className="button btn">
To the Top
</button>
</div>
</div>
);
}

export default CardMain;
149 changes: 149 additions & 0 deletions src/Components/Cardcontainer.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,149 @@
import React, { useState, useEffect, useRef } from "react";
import { BsFillHeartFill } from "react-icons/bs";
import { Link } from "react-router-dom";

const Cardcontainer = ({features}) => {
const [isVisible, setIsVisible] = useState(
new Array(features.length).fill(false)
);
const containerRef = useRef(null);
let hideTimeout;

useEffect(() => {
return () => {
clearTimeout(hideTimeout);
};
}, []);

const handleMouseOver = (index) => {
clearTimeout(hideTimeout);
setIsVisible((prevIsVisible) => {
const newIsVisible = [...prevIsVisible];
newIsVisible[index] = true;
return newIsVisible;
});
};

const handleMouseOut = (index) => {
hideTimeout = setTimeout(() => {
setIsVisible((prevIsVisible) => {
const newIsVisible = [...prevIsVisible];
newIsVisible[index] = false;
return newIsVisible;
});
}, 200);
};

const scrollToTop = () => {
if (containerRef.current) {
containerRef.current.scrollTo({
top: 0,
behavior: "smooth",
});
}

window.scrollTo({
top: 0,
behavior: "smooth",
});
};

return (
<div
className="card"
ref={containerRef}
style={{ overflowY: "auto", maxHeight: "100vh" }}
>
{features.map((project, index) => (
<div className="card_main" key={index}>
<img
src={project.img}
alt=""
className="card_main_img"
title={project.title}
/>
<div className="card_main_name">
<h2>{project.title}</h2>
<div className="card_main_icon">
<i>
<BsFillHeartFill /> <span>{project.hearts}</span>
</i>
</div>
</div>
<div className="stat">
<div>
<p>
Developer<span>X</span>
</p>
</div>
<div>
<p>
Type of Project<span>{project.type}</span>
</p>
</div>
</div>
<div className="author" style={{ marginTop: "-12px" }}>
<div className="nameAuthor">
<p>By : &nbsp; </p>
<p
id="author_name"
onMouseOver={() => handleMouseOver(index)}
onMouseOut={() => handleMouseOut(index)}
>
{project.dev}
</p>
</div>
</div>
<div className="card_main_button" style={{ marginTop: "-16px" }}>
<Link to={`/readmore/${project.id}`} className="button btn">
Read More
</Link>
<a href="#" className="button2 btn">
Source Code
</a>
</div>

<div
className={`contBox ${isVisible[index] ? "visible" : "hidden"}`}
onMouseOver={() => handleMouseOver(index)}
onMouseOut={() => handleMouseOut(index)}
>
<div className="heading">
<img width={40} src={project.pro} alt="" />
<div className="details1">
<p id="name">@{project.dev}</p>
<p id="occupation">{project.role}</p>
</div>
</div>
<div className="details2">
<p id="info">{project.about}</p>
</div>
<div className="btnnn">
<button>Follow Me</button>
<button>
<Link to={`/profile/${project.id}`}>View Profile</Link>
</button>
</div>
</div>
</div>
))}

<div
style={{
textAlign: "center",
padding: "20px",
display: "flex",
alignItems: "center",
justifyContent: "center",
width: "100%",
}}
>
<button onClick={scrollToTop} className="button btn">
To the Top
</button>
</div>
</div>
);
};

export default Cardcontainer;
Loading