diff --git a/my-next-app/.eslintrc.json b/my-next-app/.eslintrc.json index 53124c5..55979f8 100644 --- a/my-next-app/.eslintrc.json +++ b/my-next-app/.eslintrc.json @@ -1,6 +1,6 @@ { "extends": "next/core-web-vitals", "rules": { - "no-console": "error" + "no-console": ["error", { "allow": ["error"] }] } } diff --git a/my-next-app/src/app/moviepage/page.jsx b/my-next-app/src/app/moviepage/page.jsx index 53cf43b..d77ec12 100644 --- a/my-next-app/src/app/moviepage/page.jsx +++ b/my-next-app/src/app/moviepage/page.jsx @@ -1,47 +1,78 @@ 'use client'; - -import Image from 'next/image'; - -import React, { useState } from 'react'; -import movies from '../mock_db/movies.json'; -import reviews from '../mock_db/reviews.json'; +import React, { useState, useEffect } from 'react'; +import styles from './page.module.css'; +// import movies from '../mock_db/movies.json'; +// import reviews from '../mock_db/reviews.json'; export default function MoviePage() { const [movieId, setMovieId] = useState(null); // Initial movie - const movie = movies.find((movie) => movie.id === movieId); - const movieReviews = reviews.filter((review) => review.movie_id === movieId); + const [movieData, setMovieData] = useState(null); + const [reviewData, setReviewData] = useState(null); + const options = { + method: 'GET', + headers: { + accept: 'application/json', + Authorization: + 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4OTM5NTE2MmJjNDA5MzQ2MTMyNmM5NzUyZTBkZjMzZiIsIm5iZiI6MTcyNzI1NjM4Ny41OTcyMzYsInN1YiI6IjY2Y2RkOWM2NmZkMmYwN2FiNzlkYjE3MCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.n6Dhal1cf-trWSV3ewyYHw9HMouvYGBgv-pqFu3N2B0', + }, + }; + useEffect(() => { + fetch(`https://api.themoviedb.org/3/movie/${movieId}?language=en-US`, options) + .then((response) => response.json()) + .then((data) => { + setMovieData(data); + //console.log(data); + }) + .catch((err) => console.error(err)); + }, [movieId]); + const reviews = { + method: 'GET', + headers: { + accept: 'application/json', + Authorization: + 'Bearer eyJhbGciOiJIUzI1NiJ9.eyJhdWQiOiI4OTM5NTE2MmJjNDA5MzQ2MTMyNmM5NzUyZTBkZjMzZiIsIm5iZiI6MTcyNzI1NjM4Ny41OTcyMzYsInN1YiI6IjY2Y2RkOWM2NmZkMmYwN2FiNzlkYjE3MCIsInNjb3BlcyI6WyJhcGlfcmVhZCJdLCJ2ZXJzaW9uIjoxfQ.n6Dhal1cf-trWSV3ewyYHw9HMouvYGBgv-pqFu3N2B0', + }, + }; + useEffect(() => { + fetch(`https://api.themoviedb.org/3/movie/${movieId}/reviews`, reviews) + .then((response) => response.json()) + .then((data) => { + setReviewData(data); + //console.log(data); + }) + .catch((err) => console.error(err)); + }, [movieId]); return ( -
+
{/* Movie Selector */}
- + setMovieId(Number(e.target.value))} />
- {movie ? ( - <> -

{movie.title}

-

{movie.overview}

-

Release Date: {movie.release_date}

- {movie.title} - + {movieData ? ( +
+ {movieData.title} +

{movieData.original_title}

+

{movieData.overview}

+

Release Date: {movieData.release_date}

+
) : (

Movie not found

)} -

Reviews

- {movieReviews.length > 0 ? ( - movieReviews.map((review) => ( -
-

{review.reviewer_name}

-

{review.review}

+

Reviews

+ {reviewData && reviewData.results && reviewData.results.length > 0 ? ( + reviewData.results.map((review) => ( +
+

{review.author}

+

Rating: {review.author_details?.rating ?? 'No rating'}

+

{review.content}

)) ) : ( -

No reviews found for this movie

+

No reviews found for this movie

)}
); diff --git a/my-next-app/src/app/moviepage/page.module.css b/my-next-app/src/app/moviepage/page.module.css new file mode 100644 index 0000000..d3bfde7 --- /dev/null +++ b/my-next-app/src/app/moviepage/page.module.css @@ -0,0 +1,6 @@ +.wrapper { + background: linear-gradient(150deg, #001523, #003356, #001523 90%); +} +.text{ + color: #D7DAE3 +} \ No newline at end of file