From 69b9513a19e8d0aa280bae8ec7b91dd5e81de2fa Mon Sep 17 00:00:00 2001 From: "Alberto Duarte (PWC)" Date: Mon, 9 Oct 2023 17:31:33 +0100 Subject: Second commit --- screens/home.js | 324 ++++++++++++++++++++++++++++---------------------------- 1 file changed, 162 insertions(+), 162 deletions(-) (limited to 'screens/home.js') diff --git a/screens/home.js b/screens/home.js index 184bbf9..9d5addc 100644 --- a/screens/home.js +++ b/screens/home.js @@ -1,162 +1,162 @@ -import {useCallback, useEffect, useState} from 'react'; -import { - ImageBackground, - Platform, - Pressable, - SafeAreaView, - ScrollView, - Text, - TextInput, - View, -} from 'react-native'; -import tw from 'twrnc'; -import {useDeviceContext} from 'twrnc'; -import requests from '../lib/requests'; -import PreviewCard from '../components/PreviewCard'; -import Modal from './modal'; -//ICONS -import {TvIcon} from 'react-native-heroicons/outline'; -import {MagnifyingGlassIcon} from 'react-native-heroicons/outline'; -import {ChevronDownIcon} from 'react-native-heroicons/solid'; -import {UserIcon} from 'react-native-heroicons/outline'; -import ImageColors from 'react-native-image-colors'; -import LinearGradient from 'react-native-linear-gradient'; - -const Home = ({navigation}) => { - useDeviceContext(tw); - const imgAssets = process.env.IMG_ASSETS; - const [heroMovie, setHeroMovie] = useState(); - const [heroMovieColor, setHeroMovieColor] = useState(); - const [topRatedMovies, setTopRatedMovies] = useState(); - const [isModalVisible, setModalVisible] = useState(false); - const [modalContent, setModalContent] = useState(); - - const toggleModal = (movie) => { - setModalVisible(!isModalVisible); - setModalContent(movie); -}; - - useEffect(() => { - fetch(`https://api.themoviedb.org/3/movie/top_rated?api_key=f247ff737ec8062f3b5e027789eab748&language=en`) - .then(res => res.json()) - .then(data => { - setHeroMovie(data.results[1]); - setTopRatedMovies(data.results) - }); - }, []); - - useEffect(() => { - const fetchColor = async () => { - const data = await ImageColors.getColors( - `https://image.tmdb.org/t/p/original${heroMovie?.poster_path}`, - { - fallback: '#000000', - cache: true, - key: 'unique_key', - }, - ).then(data => { - if (Platform.OS === 'ios') { - setHeroMovieColor(data.primary); - } else { - setHeroMovieColor(data.average); - } - }); - } - if (heroMovie?.poster_path != undefined) { - fetchColor() - .catch(e => { - console.log(e) - return e - }); - } - }, [heroMovie]) - - return ( - - - - - For Matias - - - - - - - - - navigation.navigate('Profile')} - style={tw`rounded bg-white/20 w-6 h-6 flex items-center justify-center`} - > - - - - - - - TV Shows - - - Movies - - - Categories - - - - - - - {heroMovieColor !== undefined && ( - - )} - - Popular on Netflix - - { - topRatedMovies?.map((movie, index) => ( - toggleModal(movie)}> - - - ))} - - - {isModalVisible && ( - - )} - - - ); -}; - -export default Home; +import {useCallback, useEffect, useState} from 'react'; +import { + ImageBackground, + Platform, + Pressable, + SafeAreaView, + ScrollView, + Text, + TextInput, + View, +} from 'react-native'; +import tw from 'twrnc'; +import {useDeviceContext} from 'twrnc'; +import requests from '../lib/requests'; +import PreviewCard from '../components/PreviewCard'; +import Modal from './modal'; +//ICONS +import {TvIcon} from 'react-native-heroicons/outline'; +import {MagnifyingGlassIcon} from 'react-native-heroicons/outline'; +import {ChevronDownIcon} from 'react-native-heroicons/solid'; +import {UserIcon} from 'react-native-heroicons/outline'; +import ImageColors from 'react-native-image-colors'; +import LinearGradient from 'react-native-linear-gradient'; + +const Home = ({navigation}) => { + useDeviceContext(tw); + const imgAssets = process.env.IMG_ASSETS; + const [heroMovie, setHeroMovie] = useState(); + const [heroMovieColor, setHeroMovieColor] = useState(); + const [topRatedMovies, setTopRatedMovies] = useState(); + const [isModalVisible, setModalVisible] = useState(false); + const [modalContent, setModalContent] = useState(); + + const toggleModal = (movie) => { + setModalVisible(!isModalVisible); + setModalContent(movie); +}; + + useEffect(() => { + fetch(`https://api.themoviedb.org/3/movie/top_rated?api_key=f247ff737ec8062f3b5e027789eab748&language=en`) + .then(res => res.json()) + .then(data => { + setHeroMovie(data.results[1]); + setTopRatedMovies(data.results) + }); + }, []); + + useEffect(() => { + const fetchColor = async () => { + const data = await ImageColors.getColors( + `https://image.tmdb.org/t/p/original${heroMovie?.poster_path}`, + { + fallback: '#000000', + cache: true, + key: 'unique_key', + }, + ).then(data => { + if (Platform.OS === 'ios') { + setHeroMovieColor(data.primary); + } else { + setHeroMovieColor(data.average); + } + }); + } + if (heroMovie?.poster_path != undefined) { + fetchColor() + .catch(e => { + console.log(e) + return e + }); + } + }, [heroMovie]) + + return ( + + + + + For Matias + + + + + + + + + navigation.navigate('Profile')} + style={tw`rounded bg-white/20 w-6 h-6 flex items-center justify-center`} + > + + + + + + + TV Shows + + + Movies + + + Categories + + + + + + + {heroMovieColor !== undefined && ( + + )} + + Popular on Netflix + + { + topRatedMovies?.map((movie, index) => ( + toggleModal(movie)}> + + + ))} + + + {isModalVisible && ( + + )} + + + ); +}; + +export default Home; -- cgit v1.2.3-54-g00ecf