You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
43 lines
1.4 KiB
43 lines
1.4 KiB
import React, { useEffect, useState } from 'react';
|
|
import { View, FlatList, TextInput, Button,Text } from 'react-native';
|
|
import { useDispatch, useSelector } from 'react-redux';
|
|
import { Weather } from '../data/stub';
|
|
import { addToFavorites } from '../redux/actions/ActionFavorites';
|
|
import { fetchFavorites } from '../thunk/favorites/thunkListFavorites';
|
|
import { insertFavorite } from '../thunk/favorites/thunkStoreFavorite';
|
|
import { fetchFavoritesByCity } from '../thunk/favorites/thunkListByCity';
|
|
import { FavoriteWeather } from '../Components/FavoriteComponent';
|
|
|
|
const Favorite = ({route}) => {
|
|
const weather : Weather = route.params.weather
|
|
|
|
const [newFavorite,setNewFavorite] = useState('');
|
|
const favorites : [Weather] = useSelector(state => state.FavoritesReducer.favorites);
|
|
const dispatch = useDispatch();
|
|
|
|
useEffect(() => {
|
|
const loadWeathers = async () => {
|
|
dispatch(fetchFavoritesByCity(weather.city.name));
|
|
};
|
|
loadWeathers();
|
|
}, [dispatch]);
|
|
return (
|
|
<View>
|
|
<Text>Favoris de la ville : {weather.city.name}</Text>
|
|
<FlatList
|
|
data={favorites}
|
|
keyExtractor={(item, index) => index.toString()}
|
|
|
|
showsHorizontalScrollIndicator={false}
|
|
renderItem={({ item }) => <FavoriteWeather weather={item} />}
|
|
/>
|
|
<TextInput
|
|
value={newFavorite}
|
|
onChangeText={text => setNewFavorite(text)}
|
|
/>
|
|
</View>
|
|
);
|
|
};
|
|
|
|
export default Favorite;
|