From 8a5b796406240ee106d0127c837e18878f15be5c Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Thu, 2 Feb 2023 19:18:18 +0100 Subject: [PATCH] try api --- api/tmdb.tsx | 20 +++--- components/ListWidget.tsx | 45 +++++++++++--- components/MovieList.tsx | 127 +++++++++++++++++++++++++++++++++----- navigation/index.tsx | 2 +- screens/HomeScreen.tsx | 2 +- 5 files changed, 161 insertions(+), 35 deletions(-) diff --git a/api/tmdb.tsx b/api/tmdb.tsx index 092d176..89f52a0 100644 --- a/api/tmdb.tsx +++ b/api/tmdb.tsx @@ -1,11 +1,15 @@ import axios from "axios"; -export default axios.create({ - baseURL: 'https://api.themoviedb.org/3', - headers:{ - Accept: "application/json" - }, - params: { - api_key: 'a133422b5b1f22428e8074470d321865' +class apiTMBD { + api_key: string = "a133422b5b1f22428e8074470d32186"; + base_url: string = "https://api.themoviedb.org/3/"; + + apiTMDB() { + }; + + getPopularMovie() { + } -}) \ No newline at end of file + + +} \ No newline at end of file diff --git a/components/ListWidget.tsx b/components/ListWidget.tsx index ca7e7f9..321ee3e 100644 --- a/components/ListWidget.tsx +++ b/components/ListWidget.tsx @@ -4,8 +4,12 @@ import * as React from "react"; type ListWidgetProps = { - imageURL : string - name : String + imageURL: string + name: String + + runtime: number + + director: string } @@ -21,18 +25,43 @@ const styles = StyleSheet.create({ export function ListWidget(props: ListWidgetProps) { + + function formatTime(time: number) { + const hours = Math.floor(time / 60); + const minutes = time % 60; + return `${hours}h ${minutes < 10 ? `0${minutes}` : minutes}m`; + } + return ( - + - - {props.name} - {props.name} - + + {props.director} + {formatTime(props.runtime)} + diff --git a/components/MovieList.tsx b/components/MovieList.tsx index 9416bc7..041c4b9 100644 --- a/components/MovieList.tsx +++ b/components/MovieList.tsx @@ -1,25 +1,118 @@ import {useEffect, useState} from "react"; -import {View} from "react-native"; +import {FlatList, View} from "react-native"; import {ListWidget} from "./ListWidget"; import tmdb from "../api/tmdb" +import axios from "axios"; + +interface idMovie { + id: string + +} + + +interface Cast { + cast: string + +} + +interface People { + name: string + job: string + +} + +interface Movie { + id: string + original_title: string + poster_path: string + runtime: number + vote_average: number + + director: string + + +} + +const opt = { + method: 'GET', + url: 'https://api.themoviedb.org/3/trending/all/day', + headers: { + Accept: "application/json" + }, + params: { + api_key: 'a133422b5b1f22428e8074470d321865' + } +} +const opt2 = { + method: 'GET', + url: 'https://api.themoviedb.org/3/trending/all/day', + headers: { + Accept: "application/json" + }, + params: { + api_key: 'a133422b5b1f22428e8074470d321865' + } +} const MovieList = () => { - const [movies,setMovies] = useState([]) - - useEffect(()=>{ - const fetchMovies = async() =>{ - const {data}= await tmdb.get("movie/popular") - setMovies(data.results) - } - - fetchMovies() - },[]) - - return - {movies.map((movie, index)=>{ - return - })} - + const [movies, setMovies] = useState([]) + const movielist: Movie[] = [] + + useEffect(() => { + axios.get("https://api.themoviedb.org/3/trending/all/day?api_key=a133422b5b1f22428e8074470d321865").then(async (response) => { + await response.data.results.forEach(async function (id: idMovie) { + console.log(id.id); + try { + const sheet = await axios.get(`https://api.themoviedb.org/3/movie/${id.id}?api_key=a133422b5b1f22428e8074470d321865&language=en-US`); + if (sheet && sheet.status == 200) { + movielist.push(sheet.data); + setMovies(movielist); + + + } + + } catch (e) { + console.log(e); + } + }) + }) + }, []) + + useEffect(() => { + movies.forEach(async function (movie: Movie) { + console.log("-----------------------------"); + /*console.log(movie);*/ + axios.get(`https://api.themoviedb.org/3/movie/${movie.id}/credits?api_key=a133422b5b1f22428e8074470d321865&language=en-US`).then((response) => { + response.data.results.forEach(function (cast: Cast) { + console.log(cast.cast); + try { + /*const sheet = axios.get(`https://api.themoviedb.org/3/movie/${id.id}?api_key=a133422b5b1f22428e8074470d321865&language=en-US`); + if (sheet && sheet.status == 200) { + movielist.push(sheet.data); + setMovies(movielist); + + + }*/ + + } catch (e) { + console.log(e); + } + }) + + }); + }) + + + }) + return ( + item.id} + renderItem={({item}) => }> + + ) } export default MovieList; \ No newline at end of file diff --git a/navigation/index.tsx b/navigation/index.tsx index 1f31fe0..6872fa4 100644 --- a/navigation/index.tsx +++ b/navigation/index.tsx @@ -61,7 +61,7 @@ function BottomTabNavigator() { return ( + {props.name}