Skip to content

Commit ef27196

Browse files
author
Hannah Dunsmore
committed
integrated RoverImages Element
1 parent c0abfc6 commit ef27196

File tree

4 files changed

+24
-13
lines changed

4 files changed

+24
-13
lines changed

src/Components/RoverDetails/RoverDetails.tsx

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import spiritButton from "../../Assets/Images/spirit_button.png";
55
import curiosityButton from "../../Assets/Images/curiosity_button.png";
66
import opportunityButton from "../../Assets/Images/Opportunity_button.png";
77
import "./RoverDetails.scss";
8+
import RoverImages from "../RoverImages/RoverImages";
89

910
export enum rovers {
1011
CURIOSITY = "curiosity",
@@ -77,6 +78,7 @@ function RoverDetails() {
7778
</button>
7879
</div>
7980
<MissionManifest roverType={rover} />
81+
<RoverImages roverType={rover}/>
8082
</div>
8183
);
8284
}

src/Components/RoverImages/RoverImage.spec.tsx

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
import React from "react";
22
import { fireEvent, render, waitFor } from "@testing-library/react";
33
import RoverImages from "./RoverImages";
4+
import { rovers } from "../RoverDetails/RoverDetails";
5+
46

57
const photo_mock_data = {
68
photos: [
@@ -37,7 +39,7 @@ describe("Testing the rover image displayed on page load", () => {
3739
});
3840
});
3941
test("Testing the rover image displayed on page load", async () => {
40-
render(<RoverImages name="curiosity" />);
42+
render(<RoverImages roverType={rovers.CURIOSITY} />);
4143

4244
await waitFor(() => {
4345
const testImage = document.querySelector("img") as HTMLImageElement;
@@ -49,7 +51,7 @@ describe("Testing the rover image displayed on page load", () => {
4951
});
5052

5153
test("Testing the rover image is displayed when next is clicked", async () => {
52-
render(<RoverImages name="curiosity" />);
54+
render(<RoverImages roverType={rovers.CURIOSITY} />);
5355
await waitFor(() => {
5456
const firstTestImage = document.querySelector("img") as HTMLImageElement;
5557
const firstTestImageDiv = firstTestImage.parentElement?.parentElement;

src/Components/RoverImages/RoverImages.scss

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@ body {
44
}
55

66
.sliderContainer {
7-
max-width: 30%;
7+
width: 42.5vw;
88
margin: auto;
9-
padding: 40px;
9+
padding: 20px 40px 30px 40px;
1010
}
1111

1212
.error {
@@ -15,14 +15,20 @@ body {
1515
}
1616

1717

18-
@media screen and (max-width: 1000px) {
18+
@media (max-width: 898px) {
1919
.sliderContainer {
20-
max-width: 60%;
20+
width: 55vw;
2121
}
2222
}
2323

24-
@media screen and (max-width: 600px) {
24+
@media (max-width: 656px) {
2525
.sliderContainer {
26-
max-width: 80%;
26+
width: 65vw;
27+
}
28+
}
29+
30+
@media (max-width: 320px) {
31+
.sliderContainer {
32+
width: 70vw;
2733
}
2834
}

src/Components/RoverImages/RoverImages.tsx

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ import "slick-carousel/slick/slick.css";
44
import "slick-carousel/slick/slick-theme.css";
55
import "./RoverImages.scss";
66
import { ClipLoader } from "react-spinners";
7+
import { rovers, MissionManifestProps } from "../RoverDetails/RoverDetails";
78

89
type RoverResponse = {
910
id: number;
@@ -12,12 +13,12 @@ type RoverResponse = {
1213

1314
const api = "fCp5fNsscdDmov0Vw4lpU4bOkdMTCuCA9tnoKgYH";
1415

15-
function RoverImages(props: { name: string }) {
16+
function RoverImages(props: MissionManifestProps) {
1617
const [roverResponse, setRoverResponse] = useState<RoverResponse[]>();
1718
const [error, setError] = useState<string>("");
1819
const [isLoading, setLoading] = useState<boolean>(false);
1920

20-
const altText = `Photo taken by the Mars Rover ${props.name}`;
21+
const altText = `Photo taken by the Mars Rover ${props.roverType}`;
2122

2223
const sliderSettings = {
2324
dots: false,
@@ -38,12 +39,12 @@ function RoverImages(props: { name: string }) {
3839
try {
3940
setLoading(true);
4041
const manifestResponse = await fetch(
41-
`https://api.nasa.gov/mars-photos/api/v1/manifests/${props.name}?api_key=${api}`,
42+
`https://api.nasa.gov/mars-photos/api/v1/manifests/${props.roverType}?api_key=${api}`,
4243
);
4344
const manifestData = await manifestResponse.json();
4445

4546
const photoResponse = await fetch(
46-
`https://api.nasa.gov/mars-photos/api/v1/rovers/${props.name}/photos?earth_date=${manifestData.photo_manifest.max_date}&api_key=${api}`,
47+
`https://api.nasa.gov/mars-photos/api/v1/rovers/${props.roverType}/photos?earth_date=${manifestData.photo_manifest.max_date}&api_key=${api}`,
4748
);
4849
const photoData = await photoResponse.json();
4950

@@ -58,7 +59,7 @@ function RoverImages(props: { name: string }) {
5859
};
5960

6061
fetchData();
61-
}, [props.name]);
62+
}, [props.roverType]);
6263

6364
if (error) {
6465
return (

0 commit comments

Comments
 (0)