Adding and removing favs

pull/5/head
Corentin RICHARD 2 years ago
parent 88a6612e77
commit 3c08ebeeb4

@ -1,3 +1,4 @@
import { Card } from '../../models/Card'
import { CardProps } from '../../props/favprops'
import {FETCH_DATA, ADD_FAVORITE_DATA} from '../constants'
@ -13,10 +14,16 @@ export default appReducer = (state = initialState, action) => {
case ADD_FAVORITE_DATA:
const a : CardProps = action.payload
if(a.route.bool ==false){
//@ts-ignore
const tab = state.favoriteCards.concat([a.route.card])
console.log(state.favoriteCards)
return {...state, favoriteCards : tab};
const t : Card[] = state.favoriteCards
if(t.every((elem) => elem != a.route.card)){
//@ts-ignore
const tab = state.favoriteCards.concat([a.route.card])
console.log(state.favoriteCards)
return {...state, favoriteCards : tab};
}
return {...state}
}
else{
const tab = state.favoriteCards.filter((item) => item!= a.route.card)

@ -27,7 +27,7 @@ import Item from '../components/ListItemComponent';
export default function ListScreen({navigation}){
//@ts-ignore
let nList = useSelector(state => state.appReducer.favoriteCards);
var nList : Card[] = useSelector(state => state.appReducer.favoriteCards);
console.log(nList)
const [searchValue, setSearchValue] = useState('');
@ -51,7 +51,6 @@ export default function ListScreen({navigation}){
card: item,
bool: true
}} />
<Text>"a"</Text>
</TouchableHighlight>
}
keyExtractor={(item: Card) => item.id.toString()}

Loading…
Cancel
Save