parent
731c69ccc6
commit
88a6612e77
@ -1,17 +1,53 @@
|
|||||||
import { View } from 'react-native';
|
import { useDispatch } from "react-redux";
|
||||||
import { Image } from 'react-native';
|
import { Card } from "../models/Card";
|
||||||
|
import { setFavList } from "../redux/actions/action_setFavList";
|
||||||
|
import { ImageBackground, TouchableHighlight, View } from "react-native";
|
||||||
|
import React, { useEffect } from "react";
|
||||||
|
import {CardProps} from "../props/favprops"
|
||||||
|
import { FontAwesome } from '@expo/vector-icons';
|
||||||
|
import { StyleSheet} from 'react-native';
|
||||||
|
|
||||||
|
export default function Item(props: CardProps){ // a mettre dans components et definir une props pour passer le param
|
||||||
|
|
||||||
type ItemProps = {
|
const {route} = props;
|
||||||
url : string //Image URL
|
const item: Card = route.card;
|
||||||
}
|
const bool: boolean = route.bool;
|
||||||
|
const dispatch = useDispatch()
|
||||||
|
|
||||||
|
const HandleAddFav = (props : CardProps) => {
|
||||||
|
console.log("add new card")
|
||||||
|
dispatch(setFavList(props));
|
||||||
|
}
|
||||||
|
return(
|
||||||
|
|
||||||
|
/* dispatch , */
|
||||||
|
<View style={styles.item}>
|
||||||
|
<ImageBackground source={{uri:item.img}} style={{flex:1, minHeight:250, minWidth:180}}>
|
||||||
|
<TouchableHighlight style={item.fav?styles.favoriteButtonFav:styles.favoriteButtonNonFav} onPress={() => HandleAddFav(props)} >
|
||||||
|
<FontAwesome name="heart-o" size={50} color="#fff" />
|
||||||
|
</TouchableHighlight>
|
||||||
|
</ImageBackground>
|
||||||
|
|
||||||
export function ListItemComponent(props : ItemProps){
|
|
||||||
return (
|
|
||||||
<View>
|
|
||||||
<Image
|
|
||||||
source={{uri: props.url}}
|
|
||||||
style={{flex:1, minHeight:250, minWidth:180}}/>
|
|
||||||
</View>
|
</View>
|
||||||
)
|
);
|
||||||
}
|
}
|
||||||
|
const styles = StyleSheet.create({
|
||||||
|
item: {
|
||||||
|
|
||||||
|
},
|
||||||
|
favoriteButtonNonFav: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
backgroundColor: 'red',
|
||||||
|
borderRadius: 50,
|
||||||
|
padding: 10,
|
||||||
|
},
|
||||||
|
favoriteButtonFav: {
|
||||||
|
position: 'absolute',
|
||||||
|
top: 10,
|
||||||
|
right: 10,
|
||||||
|
backgroundColor: 'red',
|
||||||
|
borderRadius: 50,
|
||||||
|
padding: 10,
|
||||||
|
},});
|
@ -0,0 +1,8 @@
|
|||||||
|
import { Card } from "../models/Card";
|
||||||
|
|
||||||
|
export interface CardProps{
|
||||||
|
route : {
|
||||||
|
card: Card;
|
||||||
|
bool: boolean;
|
||||||
|
}
|
||||||
|
}
|
@ -1,8 +1,10 @@
|
|||||||
|
import { Card } from '../../models/Card';
|
||||||
|
import { CardProps } from '../../props/favprops';
|
||||||
import {ADD_FAVORITE_DATA, FETCH_DATA} from '../constants';
|
import {ADD_FAVORITE_DATA, FETCH_DATA} from '../constants';
|
||||||
|
|
||||||
export const setFavList = (List: String[]) => {
|
export const setFavList = (props : CardProps) => {
|
||||||
return {
|
return {
|
||||||
type: ADD_FAVORITE_DATA,
|
type: ADD_FAVORITE_DATA,
|
||||||
payload: List,
|
payload: props,
|
||||||
};
|
};
|
||||||
}
|
}
|
Loading…
Reference in new issue