From 62584127bc73b13ba0d302e897f7f5c8dd0788b5 Mon Sep 17 00:00:00 2001 From: Lucas Delanier Date: Tue, 28 Feb 2023 00:29:32 +0100 Subject: [PATCH] add review and recommendations to info page --- model/MinimalMovie.tsx | 16 ++++++++ model/review.tsx | 28 ++++++++++++++ screens/InfoScreen.tsx | 86 ++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 126 insertions(+), 4 deletions(-) create mode 100644 model/MinimalMovie.tsx create mode 100644 model/review.tsx diff --git a/model/MinimalMovie.tsx b/model/MinimalMovie.tsx new file mode 100644 index 0000000..3bc5bc5 --- /dev/null +++ b/model/MinimalMovie.tsx @@ -0,0 +1,16 @@ +class MinimalMovie { + public original_title: string + + public poster_path: string + + + constructor(original_title: string, poster_path: string) { + this.original_title = original_title; + this.poster_path = 'https://image.tmdb.org/t/p/w780' + poster_path; + + } + + +} + +export default MinimalMovie; \ No newline at end of file diff --git a/model/review.tsx b/model/review.tsx new file mode 100644 index 0000000..7bdd141 --- /dev/null +++ b/model/review.tsx @@ -0,0 +1,28 @@ +class Review { + public message: string + + public pseudo: string + + public profil_path: string + + public date: string + + + constructor(message: string, profil_path: string, date: string, pseudo: string) { + this.message = message; + if (profil_path === null) { + console.log("nulllllllllll") + this.profil_path = "https://thumbs.dreamstime.com/b/profil-vectoriel-avatar-par-d%C3%A9faut-utilisateur-179376714.jpg"; + } else { + this.profil_path = 'https://image.tmdb.org/t/p/w500' + profil_path; + } + + this.date = date.substring(0, 10); + this.pseudo = pseudo; + + } + + +} + +export default Review; \ No newline at end of file diff --git a/screens/InfoScreen.tsx b/screens/InfoScreen.tsx index 9cbe46a..b4b7d1c 100644 --- a/screens/InfoScreen.tsx +++ b/screens/InfoScreen.tsx @@ -9,7 +9,7 @@ import { Image, ImageBackground, SafeAreaView, - ActivityIndicator, FlatList + ActivityIndicator, FlatList, TouchableHighlight } from 'react-native'; import {RootStackScreenProps} from "../types"; import {useSafeAreaInsets} from "react-native-safe-area-context"; @@ -23,6 +23,9 @@ import config from "../constants/config"; import YoutubeIframe from "react-native-youtube-iframe"; import Icon from "react-native-ionicons"; import Ionicons from "@expo/vector-icons/Ionicons"; +import MinimalMovie from "../model/MinimalMovie"; +import {ListWidget} from "./WatchLaterScreen"; +import Review from "../model/review"; export default function InfoScreen({navigation, route}: RootStackScreenProps<'Info'>) { const item: Movie = route.params.item @@ -36,6 +39,8 @@ export default function InfoScreen({navigation, route}: RootStackScreenProps<'In }, }); const [trailerPath, setTrailerPath] = useState(""); + const [similarMovies, setsimilarMovies] = useState([]); + const [review, setReview] = useState([]); const getTriller = async () => { const trailerResponse = (await fetch(config.base_url + "movie/" + item.id + "/videos?api_key=" + config.api_key + "&language=fr-FR")); @@ -50,10 +55,33 @@ export default function InfoScreen({navigation, route}: RootStackScreenProps<'In setTrailerPath(trailer_key); } - useEffect(() => { + const getSimilarMovies = async () => { + const SimilarMoviesResponse = (await fetch(config.base_url + "movie/" + item.id + "/recommendations?api_key=" + config.api_key + "&language=fr-FR")); + + const SimilarMoviesJson = await SimilarMoviesResponse.json(); + const SimilarMoviesList = SimilarMoviesJson.results.slice(0, 10).map((elt) => { + return new MinimalMovie(elt["original_title"], elt["poster_path"]) + }); + console.log("similar", SimilarMoviesList); + setsimilarMovies(SimilarMoviesList); + } + const getReview = async () => { + const ReviewResponse = (await fetch(config.base_url + "movie/" + item.id + "/reviews?api_key=" + config.api_key + "&language=us-EN&page=1")); + + const ReviewJson = await ReviewResponse.json(); + const ReviewList = ReviewJson.results.map((elt) => { + + return new Review(elt["content"], elt["author_details"].avatar_path, elt["created_at"], elt["author"]) + }); + console.log("review", ReviewList); + setReview(ReviewList); + } + useEffect(() => { + getReview(); getTriller(); + getSimilarMovies(); }, []); function formatTime(time: number) { @@ -94,8 +122,8 @@ export default function InfoScreen({navigation, route}: RootStackScreenProps<'In navigation.goBack()} style={{zIndex: 100}}> - - + + {item.original_title} @@ -123,6 +151,56 @@ export default function InfoScreen({navigation, route}: RootStackScreenProps<'In + + {similarMovies.length !== 0 && ( + <> + Recommandations + item.original_title} + renderItem={({item}) => + + + {item.original_title} + + } + /> + + + )} + {review.length !== 0 && ( + <> + Commentaires + item.profil_path} + renderItem={({item}) => + + + + + + {item.pseudo} + {item.date} + + + + + {item.message} + + } + /> + + + )} + +