Skip to content

Commit 803d481

Browse files
committed
feat now custom images for contact section can be added
1 parent fc69340 commit 803d481

File tree

2 files changed

+35
-6
lines changed

2 files changed

+35
-6
lines changed

public/custom-avatar.png

755 KB
Loading

src/components/githubProfileCard/GithubProfileCard.js

Lines changed: 35 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,42 @@
1-
import React from "react";
1+
import React, { useState, useEffect } from "react";
22
import "./GithubProfileCard.scss";
33
import SocialMedia from "../../components/socialMedia/SocialMedia";
4-
import {contactInfo, isHireable} from "../../portfolio";
4+
import { contactInfo, isHireable } from "../../portfolio";
55
import emoji from "react-easy-emoji";
6-
import {Fade} from "react-reveal";
6+
import { Fade } from "react-reveal";
7+
8+
const useCustomAvatar = process.env.REACT_APP_USE_CUSTOM_AVATAR === "true";
9+
10+
export default function GithubProfileCard({ prof }) {
11+
const [customImageExists, setCustomImageExists] = useState(false);
12+
const [avatarSrc, setAvatarSrc] = useState(prof.avatarUrl);
713

8-
export default function GithubProfileCard({prof}) {
914
if (isHireable) {
1015
prof.hireable = "Yes";
1116
} else {
1217
prof.hireable = "No";
1318
}
19+
20+
useEffect(() => {
21+
if (useCustomAvatar) {
22+
const candidateSrc = "/custom-avatar.png";
23+
24+
const img = new Image();
25+
img.src = candidateSrc;
26+
27+
img.onload = () => {
28+
setCustomImageExists(true);
29+
setAvatarSrc(candidateSrc);
30+
};
31+
img.onerror = () => {
32+
setCustomImageExists(false);
33+
setAvatarSrc(prof.avatarUrl);
34+
};
35+
} else {
36+
setAvatarSrc(prof.avatarUrl);
37+
}
38+
}, [useCustomAvatar, prof.avatarUrl]);
39+
1440
return (
1541
<Fade bottom duration={1000} distance="20px">
1642
<div className="main" id="contact">
@@ -21,7 +47,7 @@ export default function GithubProfileCard({prof}) {
2147
<p className="subTitle blog-subtitle">{contactInfo.subtitle}</p>
2248
</div>
2349
<h2 className="bio-text">"{emoji(String(prof.bio))}"</h2>
24-
{prof.location !== null && (
50+
{prof.location && (
2551
<div className="location-div">
2652
<span className="desc-prof">
2753
<svg
@@ -50,10 +76,13 @@ export default function GithubProfileCard({prof}) {
5076
</div>
5177
<div className="image-content-profile">
5278
<img
53-
src={prof.avatarUrl}
79+
src={avatarSrc}
5480
alt={prof.name}
5581
className="profile-image"
5682
/>
83+
{useCustomAvatar && !customImageExists && (
84+
<p className="fallback-note">(Using GitHub avatar — custom not found)</p>
85+
)}
5786
</div>
5887
</div>
5988
</div>

0 commit comments

Comments
 (0)