File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Rex Greenway - Personal Website Code
2+
3+ Personal website written in React for projects both in software and photography.
4+
5+ ## Running
6+
7+ This repository uses simple npm as follows:
8+
9+ ` npm run dev `
Original file line number Diff line number Diff line change 2121}
2222
2323.ImageModal {
24+ background-color : white;
2425 border : 10px solid white;
2526 border-radius : 5px ;
2627 max-width : 100% ;
3334 top : 10px ;
3435 right : 10px ;
3536 cursor : pointer;
37+ }
38+
39+ .Failed {
40+ color : red;
3641}
Original file line number Diff line number Diff line change 11import { ReactNode , useEffect } from "react" ;
22import CloseRoundedIcon from "@mui/icons-material/CloseRounded" ;
3+ import { CircularProgress } from "@mui/material" ;
34
45import styles from "./Modal.module.css" ;
56
@@ -39,14 +40,22 @@ const ImageModal = ({
3940 isOpen,
4041 close,
4142} : {
42- src : string ;
43+ src ? : string ;
4344 isOpen : boolean ;
4445 close : ( ) => void ;
4546} ) => {
4647 return (
4748 isOpen && (
4849 < Modal close = { close } >
49- < img className = { styles . ImageModal } src = { src } />
50+ { ! src ? (
51+ < CircularProgress className = { styles . ImageModal } color = "inherit" />
52+ ) : src === "FAILED" ? (
53+ < div className = { `${ styles . ImageModal } ${ styles . Failed } ` } >
54+ Failed to load image.
55+ </ div >
56+ ) : (
57+ < img className = { styles . ImageModal } src = { src } />
58+ ) }
5059 </ Modal >
5160 )
5261 ) ;
Original file line number Diff line number Diff line change @@ -20,10 +20,16 @@ const Collection = () => {
2020 const [ imageSrc , setImageSrc ] = useState < string > ( "" ) ;
2121
2222 const handleOpen = ( image_name : string ) => {
23- getPhoto ( image_name ) . then ( ( image ) => {
24- setImageSrc ( image . url ) ;
25- setOpenModal ( true ) ;
26- } ) ;
23+ // Open modal immediately
24+ setOpenModal ( true ) ;
25+ getPhoto ( image_name )
26+ . then ( ( image ) => {
27+ setImageSrc ( image . url ) ;
28+ } )
29+ . catch ( ( error ) => {
30+ console . error ( "Error fetching image:" , error ) ;
31+ setImageSrc ( "FAILED" ) ;
32+ } ) ;
2733 } ;
2834
2935 if ( ! ( collectionId ! in ALBUMS ) || collectionId === undefined ) {
You can’t perform that action at this time.
0 commit comments