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.overview}
-Release Date: {movie.release_date}
-{movieData.overview}
+Release Date: {movieData.release_date}
+Movie not found
)} -{review.review}
+{review.content}
No reviews found for this movie
+No reviews found for this movie
)}