1
- import React from "react" ;
1
+ import React , { useState , useEffect } from "react" ;
2
2
import "./GithubProfileCard.scss" ;
3
3
import SocialMedia from "../../components/socialMedia/SocialMedia" ;
4
- import { contactInfo , isHireable } from "../../portfolio" ;
4
+ import { contactInfo , isHireable } from "../../portfolio" ;
5
5
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 ) ;
7
13
8
- export default function GithubProfileCard ( { prof} ) {
9
14
if ( isHireable ) {
10
15
prof . hireable = "Yes" ;
11
16
} else {
12
17
prof . hireable = "No" ;
13
18
}
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
+
14
40
return (
15
41
< Fade bottom duration = { 1000 } distance = "20px" >
16
42
< div className = "main" id = "contact" >
@@ -21,7 +47,7 @@ export default function GithubProfileCard({prof}) {
21
47
< p className = "subTitle blog-subtitle" > { contactInfo . subtitle } </ p >
22
48
</ div >
23
49
< h2 className = "bio-text" > "{ emoji ( String ( prof . bio ) ) } "</ h2 >
24
- { prof . location !== null && (
50
+ { prof . location && (
25
51
< div className = "location-div" >
26
52
< span className = "desc-prof" >
27
53
< svg
@@ -50,10 +76,13 @@ export default function GithubProfileCard({prof}) {
50
76
</ div >
51
77
< div className = "image-content-profile" >
52
78
< img
53
- src = { prof . avatarUrl }
79
+ src = { avatarSrc }
54
80
alt = { prof . name }
55
81
className = "profile-image"
56
82
/>
83
+ { useCustomAvatar && ! customImageExists && (
84
+ < p className = "fallback-note" > (Using GitHub avatar — custom not found)</ p >
85
+ ) }
57
86
</ div >
58
87
</ div >
59
88
</ div >
0 commit comments