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';
DishaDarpan marked this conversation as resolved.
Show resolved Hide resolved

interface Props {
DishaDarpan marked this conversation as resolved.
Show resolved Hide resolved
largeImageUrl: string
DishaDarpan marked this conversation as resolved.
Show resolved Hide resolved
}

export const LargeImage: React.FunctionComponent<Props> = ({ largeImageUrl }) => {
return (
<div>
<img className="large-picture" src={largeImageUrl} alt="lorem picsum" width="90%" />
DishaDarpan marked this conversation as resolved.
Show resolved Hide resolved
</div>
);
}
20 changes: 14 additions & 6 deletions src/components/photoGallery/PhotoGallery.scss
Original file line number Diff line number Diff line change
@@ -1,14 +1,22 @@
.imageGallery {
.image-container {
display: flex;
flex-direction: column;
}

.image-gallery {
display: flex;
flex-wrap: wrap;
flex-direction: row;
justify-content: space-around;
gap: 10px;
}

.spaceImage {
width: 200px;
height: 200px;
.space-image {
width: 150px;
height: 150px;
object-fit: cover;

}
}

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

export const PhotoGallery: React.FunctionComponent = () => {

const [imageUrls, setImageUrls] = useState<string[]>();
const img_urls: string[] = [];
const [largeImageUrl, setLargeImageUrl] = useState<string>("https://apod.nasa.gov/apod/image/0201/earthrise_apollo8.jpg");
DishaDarpan marked this conversation as resolved.
Show resolved Hide resolved

useEffect(() => {
const url = `https://api.nasa.gov/planetary/apod?count=50&api_key=DEMO_KEY`;

const fetchData = async () => {

useEffect(() => {
const url = `https://api.nasa.gov/planetary/apod?count=50&api_key=DEMO_KEY`;

const fetchData = async () => {
try {
const response = await fetch(url);
const json = await response.json();
json.forEach((item: {url: string}) => img_urls.push(item.url));
setImageUrls(img_urls);
} catch (error) {
console.log("error", error);
}
};

fetchData();
}, []);
const response = await fetch(url);
const json = await response.json();
setImageUrls(json.map(item => item.url));
};
fetchData();
}, []);

return (
<div className = "imageGallery">
{imageUrls?.map(url => <img className="spaceImage" src={url} alt = ""/>)}
</div>
<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>
);
};