parent
c4cb072d9b
commit
8a5b796406
@ -1,11 +1,15 @@
|
|||||||
import axios from "axios";
|
import axios from "axios";
|
||||||
|
|
||||||
export default axios.create({
|
class apiTMBD {
|
||||||
baseURL: 'https://api.themoviedb.org/3',
|
api_key: string = "a133422b5b1f22428e8074470d32186";
|
||||||
headers:{
|
base_url: string = "https://api.themoviedb.org/3/";
|
||||||
Accept: "application/json"
|
|
||||||
},
|
apiTMDB() {
|
||||||
params: {
|
};
|
||||||
api_key: 'a133422b5b1f22428e8074470d321865'
|
|
||||||
|
getPopularMovie() {
|
||||||
|
|
||||||
}
|
}
|
||||||
})
|
|
||||||
|
|
||||||
|
}
|
@ -1,25 +1,118 @@
|
|||||||
import {useEffect, useState} from "react";
|
import {useEffect, useState} from "react";
|
||||||
import {View} from "react-native";
|
import {FlatList, View} from "react-native";
|
||||||
import {ListWidget} from "./ListWidget";
|
import {ListWidget} from "./ListWidget";
|
||||||
import tmdb from "../api/tmdb"
|
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 MovieList = () => {
|
||||||
const [movies,setMovies] = useState([])
|
const [movies, setMovies] = useState<Movie[]>([])
|
||||||
|
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);
|
||||||
|
|
||||||
|
|
||||||
useEffect(()=>{
|
|
||||||
const fetchMovies = async() =>{
|
|
||||||
const {data}= await tmdb.get("movie/popular")
|
|
||||||
setMovies(data.results)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fetchMovies()
|
} 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 <View>
|
})
|
||||||
{movies.map((movie, index)=>{
|
return (
|
||||||
return <ListWidget name={Object.assign({}, movie)}></ListWidget>
|
<FlatList
|
||||||
})}
|
data={movies}
|
||||||
</View>
|
keyExtractor={item => item.id}
|
||||||
|
renderItem={({item}) => <ListWidget name={item.original_title}
|
||||||
|
imageURL={`https://image.tmdb.org/t/p/w500/${item.poster_path}`}
|
||||||
|
runtime={item.runtime} director={item.director}></ListWidget>}>
|
||||||
|
</FlatList>
|
||||||
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
export default MovieList;
|
export default MovieList;
|
Loading…
Reference in new issue