Skip to content

Commit

Permalink
add button for random
Browse files Browse the repository at this point in the history
  • Loading branch information
dorothyynwong committed Aug 2, 2024
1 parent 04441b4 commit c93ce0e
Showing 1 changed file with 17 additions and 7 deletions.
24 changes: 17 additions & 7 deletions src/images/PreviewImage.tsx
Original file line number Diff line number Diff line change
@@ -1,16 +1,24 @@
import { useState, useEffect } from "react";
import { PictureOfDay } from "./DisplayPicture";
import { fetchAPI } from "../utils/fetchData";

interface PreviewImageProp {
image: PictureOfDay;
}
import { fetchAPI, fetchRandomAPI } from "../utils/fetchData";

export function PreviewImage() {

const [myPreviewImage, setMyPreviewImage] = useState<PictureOfDay | null>(null);
const [birthday, setBirthday] = useState('');

const handleRandomButtonClick = async () => {
try {
const randomPicture = await fetchRandomAPI("https://api.nasa.gov/planetary/apod?api_key=");
setMyPreviewImage(randomPicture);
console.log(myPreviewImage);

}
catch (error) {
console.error("Error fetching today's image:", error);
}
}

const handleTodayButtonClick = async () => {
try {
const todaysPicture = await fetchAPI("https://api.nasa.gov/planetary/apod?api_key=");
Expand All @@ -34,11 +42,14 @@ export function PreviewImage() {
return (
<>
<h4>CHOOSE THE IMAGE YOU WANT TO DISPLAY:</h4>

<button type="button"
id="todays-date-button"
onClick={handleTodayButtonClick}>Today</button>

<button type="button"
id="random-button"
onClick={handleRandomButtonClick}>Random</button>

<form onSubmit={handleBirthdayFormSubmit}>
<label>Birthday</label>
<input
Expand All @@ -49,7 +60,6 @@ export function PreviewImage() {
/>
<button type="submit">Submit</button>
</form>

<img src={myPreviewImage?.url} alt={myPreviewImage?.explanation} className="preview-chosen-image" />
</>
)
Expand Down

0 comments on commit c93ce0e

Please sign in to comment.