From 72cf36e033ba794db7982befa45f035b62fa6cd2 Mon Sep 17 00:00:00 2001 From: "Alberto Duarte (PWC)" Date: Mon, 9 Oct 2023 17:32:25 +0100 Subject: Changes --- app/components/AuthContext.tsx | 25 ++++++++++++++++ app/components/Genre.tsx | 24 +++++++++++++++ app/components/Modal.tsx | 66 ++++++++++++++++++++++++++++++++++++++++++ app/components/PreviewCard.tsx | 20 +++++++++++++ 4 files changed, 135 insertions(+) create mode 100644 app/components/AuthContext.tsx create mode 100644 app/components/Genre.tsx create mode 100644 app/components/Modal.tsx create mode 100644 app/components/PreviewCard.tsx (limited to 'app/components') diff --git a/app/components/AuthContext.tsx b/app/components/AuthContext.tsx new file mode 100644 index 0000000..9c83744 --- /dev/null +++ b/app/components/AuthContext.tsx @@ -0,0 +1,25 @@ +'use client' +import { createContext, useState, useEffect } from 'react'; +import { onAuthStateChanged } from 'firebase/auth'; +import { auth } from '../../services/firebase'; + +export const AuthContext = createContext(); + +export const AuthProvider = ({ children }) => { + const [user, setUser] = useState(null); + + useEffect(() => { + const unsubscribe = onAuthStateChanged(auth, (user) => { + setUser(user); + }); + + // Cleanup the subscription when the component unmounts + return () => unsubscribe(); + }, []); + + return ( + + {children} + + ); +}; \ No newline at end of file diff --git a/app/components/Genre.tsx b/app/components/Genre.tsx new file mode 100644 index 0000000..13e7ed2 --- /dev/null +++ b/app/components/Genre.tsx @@ -0,0 +1,24 @@ +import { useEffect, useState } from "react" + +const Genres = ({id}) => { + + const [genres, setGenres] = useState() + + useEffect(() => { + fetch(`https://api.themoviedb.org/3/movie/${id}?api_key=8216fbb9997cd81a67471e6cb5a6f2df`).then((res) => res.json()).then((data) => { + setGenres(data?.genres) + }) + }, [id]) + + return ( +
+ {genres?.map((genre, index) => { + return ( +
{genre.name}
+ ) + })} +
+ ) +} + +export default Genres \ No newline at end of file diff --git a/app/components/Modal.tsx b/app/components/Modal.tsx new file mode 100644 index 0000000..e783cfa --- /dev/null +++ b/app/components/Modal.tsx @@ -0,0 +1,66 @@ +import { useEffect, useState } from 'react' +import { XMarkIcon } from '@heroicons/react/24/outline' +import Genre from './Genre' + +const baseURL = 'https://api.themoviedb.org/3/' +const API_KEY = '8216fbb9997cd81a67471e6cb5a6f2df' +const Modal = ({ modalVisible, modalContent, setModalVisible, type }) => { + const [content, setContent] = useState() + const [video, setVideo] = useState() + const [similarMovies, setSimilarMovies] = useState() + useEffect(() => { + fetch(`${baseURL}/movie/${modalContent?.id}/similar?api_key=${API_KEY}`).then(res => res.json()).then((data) => { + setSimilarMovies(data.results) + }) + }, [modalContent]) + useEffect(() => { + if (modalContent) { + fetch(`${baseURL}/${modalContent.media_type}/${modalContent.id}/videos?api_key=${API_KEY}`) + .then((res) => res.json()) + .then((data) => { + console.log('VIDEOS DATA', data.results[0].key) + setVideo(data.results[0].key) + }) +} + }, [modalContent]) + return ( +
e.target === e.currentTarget && setModalVisible(false)} + > +
+ {modalVisible && ( + + )} +
+ +

{modalContent?.original_name}{modalContent?.original_title}

+

{modalContent?.overview}

+
+
+ { + similarMovies?.map((movie, index) => ( + + +
+ ))} +
+
+
+
+ ) +} +export default Modal diff --git a/app/components/PreviewCard.tsx b/app/components/PreviewCard.tsx new file mode 100644 index 0000000..132f50a --- /dev/null +++ b/app/components/PreviewCard.tsx @@ -0,0 +1,20 @@ +const imageURL = 'https://image.tmdb.org/t/p/original'; +import Genre from "./Genre"; +const baseURL ='https://api.themoviedb.org/3/' + +const PreviewCard = ({ movie, setModalContentId, setModalVisible }) => { + return ( +
{setModalVisible(true), setModalContentId(movie)}}> +
+
+

+ {movie.original_title} + {movie.original_name} +

+ +
+
+ )} + + +export default PreviewCard \ No newline at end of file -- cgit v1.2.3-54-g00ecf