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

fix: show default avatar on image load error #1043 #1124

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
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
23 changes: 11 additions & 12 deletions public/data/Om-pawarr.json
Original file line number Diff line number Diff line change
@@ -1,14 +1,13 @@
{
"name": "Om pawar",
"location": "Maharashtra",
"bio": "A Web Developer specializing in HTML5,css, JavaScript, and front-end frameworks",
"avatar": "https://avatars.githubusercontent.com/u/124502159?s=400&u=3691e22cc07794bb421cee5c655dca4d8da244c9&v=4",
"portfolio": "",
"skills": ["Front end frameworks expertise", "AWS associate level certified", "..."],
"social": {
"GitHub": "https://github.com/Om-pawarr",
"Twitter": "https://twitter.com/@_Parth_Dwivedi_",
"LinkedIn": ""
}
"name": "Om pawar",
"location": "Maharashtra",
"bio": "A Web Developer specializing in HTML5,css, JavaScript, and front-end frameworks",
"avatar": "https://avatars.githubusercontent.com/u/124502159?s=400&u=3691e22cc07794bb421cee5c655dca4d8da244c9&v=4",
"portfolio": "",
"skills": ["Front end frameworks expertise", "AWS associate level certified", "..."],
"social": {
"GitHub": "https://github.com/Om-pawarr",
"Twitter": "https://twitter.com/@_Parth_Dwivedi_",
"LinkedIn": ""
}
}
51 changes: 25 additions & 26 deletions public/data/adityashah7867.json
Original file line number Diff line number Diff line change
@@ -1,28 +1,27 @@
{
"name": "Aditya Nikunj Shah",
"location": "Mumbai, India 🇮🇳",
"bio": "FULL STACK DEV",
"avatar": "https://adityadevappweb.s3.ap-south-1.amazonaws.com/Untitled+design.png",
"portfolio": "https://adityanshah.netlify.app/",
"skills": [
"Javascript",
"C++",
"Typescript",
"Nodejs",
"Expressjs",
"React",
"Next.Js",
"MySQL",
"MongoDB",
"Docker",
"Git",
"Tailwind CSS",
"REST APIs",
"GraphQL"
],
"social": {
"GitHub": "https://github.com/adityashah7867",
"LinkedIn": "https://www.linkedin.com/in/adi-tya-shah"
}
"name": "Aditya Nikunj Shah",
"location": "Mumbai, India 🇮🇳",
"bio": "FULL STACK DEV",
"avatar": "https://adityadevappweb.s3.ap-south-1.amazonaws.com/Untitled+design.png",
"portfolio": "https://adityanshah.netlify.app/",
"skills": [
"Javascript",
"C++",
"Typescript",
"Nodejs",
"Expressjs",
"React",
"Next.Js",
"MySQL",
"MongoDB",
"Docker",
"Git",
"Tailwind CSS",
"REST APIs",
"GraphQL"
],
"social": {
"GitHub": "https://github.com/adityashah7867",
"LinkedIn": "https://www.linkedin.com/in/adi-tya-shah"
}
}
22 changes: 11 additions & 11 deletions public/data/giuliarappo.json
Original file line number Diff line number Diff line change
@@ -1,12 +1,12 @@
{
"name": "Giulia",
"location": "Italy",
"bio": "Junior fullstack delevoper searching a project to collaborate for improve skills",
"avatar": "https://github.com/giuliarappo.png",
"portfolio": "https://github.com/giuliarappo",
"skills": ["Java", "Spring boot", "Angular", "React"],
"social": {
"GitHub": "https://github.com/<giuliarappo>",
"LinkedIn": "https://www.linkedin.com/in/<giulia-rappo>"
}
}
"name": "Giulia",
"location": "Italy",
"bio": "Junior fullstack delevoper searching a project to collaborate for improve skills",
"avatar": "https://github.com/giuliarappo.png",
"portfolio": "https://github.com/giuliarappo",
"skills": ["Java", "Spring boot", "Angular", "React"],
"social": {
"GitHub": "https://github.com/<giuliarappo>",
"LinkedIn": "https://www.linkedin.com/in/<giulia-rappo>"
}
}
2 changes: 1 addition & 1 deletion src/ProfilesList.json
Original file line number Diff line number Diff line change
Expand Up @@ -442,4 +442,4 @@
"Om-pawarr.json",
"boytur.json",
"giuliarappo.json"
]
]
20 changes: 14 additions & 6 deletions src/components/Profile/Profile.jsx
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import React, { useState } from 'react';
import React, { useState, useEffect } from 'react';
import { FaGithub, FaLinkedin } from 'react-icons/fa';
import { FaXTwitter, FaLocationDot } from 'react-icons/fa6';
import defaultAvatar from './image.png';
Expand All @@ -9,10 +9,13 @@ function Profile({ data }) {

function Card({ data }) {
const cardRef = React.useRef();
// const [imageSrc, setImageSrc] = useState(data.avatar);
// const handleImageError = () => {
// setImageSrc(defaultAvatar); // Fallback to default image
// };
const [imageSrc, setImageSrc] = useState(data.avatar);
const handleImageError = () => {
setImageSrc(defaultAvatar);
};
useEffect(() => {
setImageSrc(data.avatar);
}, [data.avatar]);

const handleWheel = (event) => {
event.stopPropagation();
Expand All @@ -36,7 +39,12 @@ function Card({ data }) {
<div className="mb-6 h-auto rounded-lg bg-white p-4 shadow dark:bg-textPrimary">
<div className="relative flex gap-4">
<div className="h-24 w-24 flex-shrink-0">
<img src={data.avatar} alt="User logo" className="h-full w-full rounded-full" />
<img
src={imageSrc + '?t=' + new Date().getTime()} // Adding timestamp to force reload
alt="User logo"
className="h-full w-full rounded-full"
onError={handleImageError}
/>
</div>
<div className="w-[55%] sm:w-[75%]">
<h3>
Expand Down