@@ -12,13 +12,13 @@ const PostImg = styled.img`
12
12
transition: opacity 400ms ease 0ms;
13
13
/* width: 100%; */
14
14
/* TODO: what exactly were these supposed to be doing? */
15
- /* top: 0;
16
- left: 0;
17
- display: block; */
15
+ /* top: 0; */
16
+ /* left: 0; */
17
+ /* display: block; */
18
18
`
19
19
const PostLqipImg = styled ( PostImg ) `
20
20
position: absolute;
21
- /* width: 100%; */
21
+ width: 100%;
22
22
/* TODO: what exactly were these supposed to be doing? */
23
23
/* transform: scale(1);
24
24
transition: visibility 0ms ease 400ms; */
@@ -27,43 +27,37 @@ const PhotoCredit = styled.p`
27
27
text-align: center;
28
28
`
29
29
30
- function PostImage ( props ) {
31
- console . log ( 'Image props : ' , props )
30
+ function PostImage ( { postImg } ) {
31
+ // console.log('postImg : ', postImg )
32
32
const [ isLoaded , setIsLoaded ] = useState ( false ) ;
33
- // const [fullImgUrl, setFullImgUrl] = useState(null)
34
- // const [lqipImgUrl, setLqipImgUrl] = useState(null)
35
- // console.log('isLoaded: ', isLoaded)
36
-
37
- // useEffect(() => {
38
- // console.log('useEffect')
39
- // }, [])
40
-
41
- // function handleOnLoad() {
42
- // console.log('handleOnLoad: ', isLoaded)
43
- // }
44
-
33
+ const { width, height } = postImg . metadata . dimensions
34
+ // console.log('with/height: ', width + "/" + height)
45
35
return (
46
36
< PostImgContainer >
47
37
< PostLqipImg
48
- src = { props . postImg . metadata . lqip }
49
- alt = { `Image of ${ props . postImg . description } by ${ props . postImg . creditLine } ` }
38
+ src = { postImg . metadata . lqip }
39
+ alt = { `Image of ${ postImg . description } by ${ postImg . creditLine } ` }
50
40
style = { { visibility : isLoaded ? "hidden" : "visible" } }
41
+ width = { width }
42
+ height = { height }
51
43
/>
52
44
53
45
< PostImg
54
46
// key set to unique value ensures that LQIP image doesn't persist on page refresh
55
47
key = { Date . now ( ) }
56
48
onLoad = { ( ) => setIsLoaded ( true ) }
57
- src = { props . postImg . url }
58
- alt = { `Image of ${ props . postImg . description } by ${ props . postImg . creditLine } ` }
49
+ src = { postImg . url }
50
+ alt = { `Image of ${ postImg . description } by ${ postImg . creditLine } ` }
59
51
// TODO: move these style tags to Styled Components?
60
52
style = { { opacity : isLoaded ? 1 : 0 } }
53
+ width = { width }
54
+ height = { height }
61
55
/>
62
56
63
57
< PhotoCredit >
64
58
Photo by
65
- < a href = { props . postImg . source . url } target = "_blank" >
66
- { props . postImg . creditLine . replace ( 'by Unsplash' , ' ' ) }
59
+ < a href = { postImg . source . url } target = "_blank" >
60
+ { postImg . creditLine . replace ( 'by Unsplash' , ' ' ) }
67
61
</ a >
68
62
on < a href = "https://unsplash.com/" target = "_blank" > Unsplash</ a >
69
63
</ PhotoCredit >
0 commit comments