import * as React from 'react';
import {
Button,
TouchableOpacity,
ScrollView,
View,
Text,
StyleSheet,
Image,
ImageBackground,
SafeAreaView,
ActivityIndicator, FlatList, Animated, Easing
} from 'react-native';
import {RootStackScreenProps} from "../types";
import {useEffect, useRef, useState} from "react";
import {useSafeAreaInsets} from "react-native-safe-area-context";
import {addMovieToWatchLater, getTrendingID, removeMovieTrending,} from "../redux/actions/actionGetTrendingID";
import {useDispatch, useSelector} from 'react-redux';
import Movie from "../model/Movie";
export default function HomeScreen({ navigation }: RootStackScreenProps<'Home'>) {
// @ts-ignore
const trendingMovies = useSelector(state => state.appReducer.trendingMovies);
//console.log("liste [0]: ", trendingMovies[0]);
const insets = useSafeAreaInsets();
const styles = StyleSheet.create({
background: {
backgroundColor: 'black',
height: '100%',
paddingTop: insets.top,
},
container:{
flex: 1,
},
filmCard: {
width: '80%',
height: '60%',
justifyContent:'center',
marginLeft:'auto',
marginRight:'auto',
borderRadius: 15,
},
image: {
position: 'absolute', top: 0, left: 0, right: 0, bottom: 0, justifyContent: 'center', alignItems: 'center',
shadowColor: "#000",
shadowOffset: {
width: 0,
height: 6,
},
shadowOpacity: 0.39,
shadowRadius: 8.30,
flex: 1,
paddingTop: 70,
alignSelf: 'center',
elevation: 13,
},
backgroundImage: {
flex: 1,
resizeMode: 'cover', // or 'stretch'
},
child: {
flex: 1,
backgroundColor: 'rgba(0,0,0,0.5)',
},
});
const dispatch = useDispatch();
useEffect(() => {
const loadTrendingID = async () => {
// @ts-ignore
await dispatch(getTrendingID());
};
//console.log("test1:", trendingMovies);
loadTrendingID();
}, [dispatch]);
type ItemProps = {
movie : Movie
}
function addWatchLater(props: Movie){
dispatch(addMovieToWatchLater(props));
dispatch(removeMovieTrending(props));
}
function popFirstTrending(props: Movie){
dispatch(removeMovieTrending(props));
}
function formatTime(time: number) {
console.log(time);
const hours = Math.floor(time / 60);
const minutes = time % 60;
return `${hours}h ${minutes < 10 ? `0${minutes}` : minutes}m`;
}
let rotateValueHolder = new Animated.Value(0);
function startImageRotateFunction(){
rotateValueHolder.setValue(0);
Animated.timing(rotateValueHolder, {
toValue: 0.5,
duration: 800,
easing: Easing.linear,
useNativeDriver: true,
}).start();}
const RotateData = rotateValueHolder.interpolate({
inputRange: [0, 1],
outputRange: ['0deg', '360deg'],
});
return(
<>
{trendingMovies.length !== 0 && (
}
/>
{trendingMovies[0].original_title}
{trendingMovies[0].release_date}
addWatchLater(trendingMovies[0])}>
popFirstTrending(trendingMovies[0]) }>
)}
>
)
}
type BadgeGenreProps = {
name : String
isSelected: Boolean
}
export function BadgeGenre(props: BadgeGenreProps) {
if(props.isSelected===false){
return (
{props.name}
);
}
else{
return (
{props.name}
);
}
}
type BadgeFilmProps = {
name : String
}
export function BadgeFilm(props: BadgeFilmProps) {
return (
{props.name}
);
}