diff --git a/redux/reducers/appReducer.tsx b/redux/reducers/appReducer.tsx index 82cac37..3d06d78 100644 --- a/redux/reducers/appReducer.tsx +++ b/redux/reducers/appReducer.tsx @@ -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) diff --git a/screens/ListFav.tsx b/screens/ListFav.tsx index 9ff355c..dfeefd1 100644 --- a/screens/ListFav.tsx +++ b/screens/ListFav.tsx @@ -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 }} /> - "a" } keyExtractor={(item: Card) => item.id.toString()}