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/browse/page.tsx | 153 ++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 153 insertions(+) create mode 100644 app/browse/page.tsx (limited to 'app/browse') diff --git a/app/browse/page.tsx b/app/browse/page.tsx new file mode 100644 index 0000000..7806738 --- /dev/null +++ b/app/browse/page.tsx @@ -0,0 +1,153 @@ +'use client' +import { link } from 'fs' +import Link from 'next/link' +import { BellIcon, MagnifyingGlassIcon, PlayIcon, ArrowSmallDownIcon} from '@heroicons/react/24/solid' +import { InformationCircleIcon} from '@heroicons/react/24/outline' +import { useEffect, useState, useContext } from 'react' +import requests from '../../services/requests' +import Image from "next/image" +import PreviewCard from '../components/PreviewCard' +import Modal from '../components/Modal' +import { auth } from '../../services/firebase'; +import { useRouter } from 'next/navigation'; +import { signOut } from 'firebase/auth'; +import { AuthContext } from '../components/AuthContext' + +// import NetflixLogo from '../../../public/images/netflix_logo.svg' +const baseURL ='https://api.themoviedb.org/3/' +const imageURL = 'https://image.tmdb.org/t/p/original' + +const Home = () => { + const router = useRouter(); + const [heroMovie, setHeroMovie] = useState() + const [trendingMovies, setTrendingMovies] = useState() + const [trendingTv, setTrendingTv] = useState() + const [modalVisible, setModalVisible] = useState(false) + const [modalContent, setModalContent] = useState() + const user = useContext(AuthContext); + + useEffect(() => { + // Check if user is authenticated + if (!user) { + // Redirect or perform any necessary action + router.push('/login'); + } else { + // User is authenticated, continue with desired logic + } + }, [user]); + + useEffect(() => { + const user = auth.currentUser; + if (!user) { + // User is not signed in, redirect to the login page + router.push('/login'); + } + }, []); + + const logoutUser = () => { + signOut(auth) + .then(() => { + console.log('User signed Out!'); + // Navigate to the home screen or other desired screen + router.push('/login'); + }) + .catch(error => { + console.error(error); + // Display an error message to the user + }); + } + + useEffect(() => { + fetch(`${baseURL}${requests.fetchTopRated}`).then(res => res.json()).then((data) => { + setHeroMovie(data.results[3]) + }) + }, []) + useEffect(() => { + fetch(`${baseURL}${requests.fetchTrendingMovies}`).then(res => res.json()).then((data) => { + setTrendingMovies(data.results) + console.log(data.results) + }) + }, []) + useEffect(() => { + fetch(`${baseURL}${requests.fetchTrendingTv}`).then(res => res.json()).then((data) => { + setTrendingTv(data.results) + }) + }, []) + + return ( +
+
+
+ SVG image + Home + TV Shows + Movies + News & Popular + My List + Browse by Language +
+
+ + Kids + +
+ + + +
+ +
+
+
+
+ SVG image +

MOVIES

+
+
+ {heroMovie?.original_title} +
+
+ SVG image +

#1 in TV Shows Today

+
+
+

+ {heroMovie?.overview} +

+
+
+ + +
+
+
+

Popular on Netflix

+
+ { + trendingMovies?.map((movie, index) => ( + + ))} +
+
+
+

Tv Shows

+
+ { + trendingTv?.map((movie, index) => ( + + ))} +
+
+ +
+
+
+
+
+ ) +} +export default Home; \ No newline at end of file -- cgit v1.2.3-54-g00ecf