Skip to content
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
Binary file added public/custom-avatar.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
41 changes: 34 additions & 7 deletions src/components/githubProfileCard/GithubProfileCard.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,42 @@
import React from "react";
import React, {useState, useEffect} from "react";
import "./GithubProfileCard.scss";
import SocialMedia from "../../components/socialMedia/SocialMedia";
import {contactInfo, isHireable} from "../../portfolio";
import emoji from "react-easy-emoji";
import {Fade} from "react-reveal";

const useCustomAvatar = process.env.REACT_APP_USE_CUSTOM_AVATAR === "true";

export default function GithubProfileCard({prof}) {
const [customImageExists, setCustomImageExists] = useState(false);
const [avatarSrc, setAvatarSrc] = useState(prof.avatarUrl);

if (isHireable) {
prof.hireable = "Yes";
} else {
prof.hireable = "No";
}

useEffect(() => {
if (useCustomAvatar) {
const candidateSrc = "/custom-avatar.png";

const img = new Image();
img.src = candidateSrc;

img.onload = () => {
setCustomImageExists(true);
setAvatarSrc(candidateSrc);
};
img.onerror = () => {
setCustomImageExists(false);
setAvatarSrc(prof.avatarUrl);
};
} else {
setAvatarSrc(prof.avatarUrl);
}
}, [useCustomAvatar, prof.avatarUrl]);

return (
<Fade bottom duration={1000} distance="20px">
<div className="main" id="contact">
Expand All @@ -21,7 +47,7 @@ export default function GithubProfileCard({prof}) {
<p className="subTitle blog-subtitle">{contactInfo.subtitle}</p>
</div>
<h2 className="bio-text">"{emoji(String(prof.bio))}"</h2>
{prof.location !== null && (
{prof.location && (
<div className="location-div">
<span className="desc-prof">
<svg
Expand Down Expand Up @@ -49,11 +75,12 @@ export default function GithubProfileCard({prof}) {
<SocialMedia />
</div>
<div className="image-content-profile">
<img
src={prof.avatarUrl}
alt={prof.name}
className="profile-image"
/>
<img src={avatarSrc} alt={prof.name} className="profile-image" />
{useCustomAvatar && !customImageExists && (
<p className="fallback-note">
(Using GitHub avatar — custom not found)
</p>
)}
</div>
</div>
</div>
Expand Down