-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
6f86c94
commit de15ffd
Showing
5 changed files
with
132 additions
and
35 deletions.
There are no files selected for viewing
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
import React, { useState, useEffect } from "react"; | ||
import { useParams } from "react-router-dom"; | ||
|
||
const MovieDetails = () => { | ||
const { imdbID } = useParams(); | ||
const [movieDetails, setMovieDetails] = useState(null); | ||
|
||
useEffect(() => { | ||
const API_URL = `https://www.omdbapi.com?apikey=128dc7d1&i=${imdbID}`; // Use the IMDb ID to fetch movie details | ||
|
||
const fetchMovieDetails = async () => { | ||
try { | ||
const response = await fetch(API_URL); | ||
if (!response.ok) { | ||
throw new Error("Network response was not ok"); | ||
} | ||
const data = await response.json(); | ||
setMovieDetails(data); | ||
} catch (error) { | ||
console.error("Error fetching movie details:", error); | ||
} | ||
}; | ||
|
||
fetchMovieDetails(); | ||
}, [imdbID]); | ||
|
||
return ( | ||
<div className="movie-details"> | ||
{movieDetails ? ( | ||
<div> | ||
<h2>{movieDetails.Title}</h2> | ||
<p>{movieDetails.Plot}</p> | ||
<p>Director: {movieDetails.Director}</p> | ||
<p>Actors: {movieDetails.Actors}</p> | ||
<p>Genre: {movieDetails.Genre}</p> | ||
<p>Runtime: {movieDetails.Runtime}</p> | ||
<p>IMDb Rating: {movieDetails.imdbRating}</p> | ||
</div> | ||
) : ( | ||
<div className="empty"> | ||
<h2>Loading movie details...</h2> | ||
</div> | ||
)} | ||
</div> | ||
); | ||
}; | ||
|
||
export default MovieDetails; |