Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Mm 49 large image #22

Open
wants to merge 12 commits into
base: staging
Choose a base branch
from
13 changes: 13 additions & 0 deletions src/components/photoGallery/LargeImage.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import React from "react";

interface LargeImageProps {
largeImageUrl: string;
NickOsman11 marked this conversation as resolved.
Show resolved Hide resolved
}

export const LargeImage: React.FunctionComponent<LargeImageProps> = ({ largeImageUrl }) => {
return (
<div>
<img className="large-picture" src={largeImageUrl} alt="Large Picture" width="90%" />
NickOsman11 marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
11 changes: 10 additions & 1 deletion src/components/photoGallery/PhotoGallery.scss
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
.image-container {
display: flex;
flex-direction: column;
}

.image-gallery {
display: flex;
flex-wrap: wrap;
Expand All @@ -9,5 +14,9 @@
.space-image {
width: 200px;
height: 200px;
object-fit: cover;
object-fit: cover;
}

.large-picture {
padding: 5%;
}
18 changes: 12 additions & 6 deletions src/components/photoGallery/PhotoGallery.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import React, { useState, useEffect } from "react";
import "./PhotoGallery.scss";
import { LargeImage } from "./LargeImage";

interface Apod {
date: string;
Expand All @@ -13,6 +14,7 @@ interface Apod {

export const PhotoGallery: React.FunctionComponent = () => {
const [imageUrls, setImageUrls] = useState<string[]>();
const [largeImageUrl, setLargeImageUrl] = useState("https://apod.nasa.gov/apod/image/0201/earthrise_apollo8.jpg");

useEffect(() => {
const url = `https://api.nasa.gov/planetary/apod?count=50&api_key=DEMO_KEY`;
Expand All @@ -27,12 +29,16 @@ export const PhotoGallery: React.FunctionComponent = () => {
}, []);

return (
<div className="image-gallery">
{imageUrls === undefined ? (
<p>Loading....</p>
) : (
imageUrls.map((url) => <img className="space-image" src={url} alt="" />)
)}
<div className="image-container">
<LargeImage largeImageUrl={largeImageUrl} />
<div className="image-gallery">
{
imageUrls === undefined
? <p>Loading....</p>
: imageUrls.map(url => <img
onClick={() => { setLargeImageUrl(url); window.scrollTo(0, 0) }}
className="space-image" src={url} alt="" />)}
NickOsman11 marked this conversation as resolved.
Show resolved Hide resolved
</div>
</div>
);
};