diff --git a/donutshop/app/components/FavCard.tsx b/donutshop/app/components/FavCard.tsx new file mode 100644 index 0000000..4a85adc --- /dev/null +++ b/donutshop/app/components/FavCard.tsx @@ -0,0 +1,60 @@ +import { ImageProps, StyleSheet, Text, View } from 'react-native' +import React from 'react' +import FavImgBackground from "../components/FavImgBackground"; + + +interface FavoritesItemCardProps { + id: string; + image_item: ImageProps; + name: string; + donutname: string; + type: string; + calories: string + average_rating: number; + ratings_count: string; + description: string; + favourite: boolean; + ToggleFavouriteItem: any; + } + +const FavCard: React.FC = ({ + id, + image_item, + name, + donutname, + type, + calories, + average_rating, + ratings_count, + description, + favourite, + ToggleFavouriteItem, +}) => { + + + return ( + + + + {description} + + + ) +} + +export default FavCard + +const styles = StyleSheet.create({}) \ No newline at end of file diff --git a/donutshop/app/components/FavImgBackground.tsx b/donutshop/app/components/FavImgBackground.tsx new file mode 100644 index 0000000..068f998 --- /dev/null +++ b/donutshop/app/components/FavImgBackground.tsx @@ -0,0 +1,79 @@ +import { ImageBackground, ImageProps, Pressable, StyleSheet, Text, View } from 'react-native' +import React from 'react' +import { AntDesign } from '@expo/vector-icons'; + + +interface FavImgBackgroundProps { + EnableBackHandler: boolean; + id: string; + image_item: ImageProps; + name: string; + donutname: string; + type: string; + calories: string; + average_rating: number; + ratings_count: string; + description: string; + favourite: boolean; + ToggleFavourite: any; + BackHandler?: any; + } + + +const FavImgBackground: React.FC = ({ + EnableBackHandler, + id, + image_item, + name, + donutname, + calories, + type, + average_rating, + ratings_count, + description, + favourite, + ToggleFavourite, + BackHandler, + +}) => { + + return ( + + + {EnableBackHandler? ( + + {BackHandler()}}> + + + {ToggleFavourite(favourite, type, id);}}> + + + + ):( + + {ToggleFavourite(favourite, type, id);}}> + + + + )} + + + {donutname || name} + + + {calories} calories + + + {average_rating} + ({ratings_count}) + + + + + + ) +} + +export default FavImgBackground + +const styles = StyleSheet.create({}) \ No newline at end of file diff --git a/donutshop/app/screen/Cart.tsx b/donutshop/app/screen/Cart.tsx index 578eb57..4aee765 100644 --- a/donutshop/app/screen/Cart.tsx +++ b/donutshop/app/screen/Cart.tsx @@ -1,7 +1,6 @@ import { View, Text, ScrollView, Image, Pressable} from 'react-native' import React from 'react' import { useStore } from '../store/store'; -import {useBottomTabBarHeight} from '@react-navigation/bottom-tabs'; import Payment from '../components/Payment'; import CartItem from '../components/CartItem'; @@ -15,13 +14,22 @@ const Cart = ({navigation, route}: any) => { const addCartItemQuantity = useStore((state: any) => state.addCartItemQuantity); const removeCartItemQuantity = useStore((state: any) => state.removeCartItemQuantity); const calculateCartPrice = useStore((state: any) => state.calculateCartPrice); - - const tabBarHeight = useBottomTabBarHeight(); //console.log("CartList =", CartList.length) const buttonPressHandler = () => { navigation.push('payment'); } + //add to cart functionality + const addCartItemQuantityHandler = (id: string, size: string) => { + addCartItemQuantity(id, size); + calculateCartPrice(); + }; + //remove from cart functionality + const removeCartItemQuantityHandler = (id: string, size: string) => { + removeCartItemQuantity(id, size); + calculateCartPrice(); + }; + return ( @@ -32,12 +40,14 @@ const Cart = ({navigation, route}: any) => { {CartList.length == 0 ? ( - You bag is empty! + Your cart is empty! ):( {CartList.map((data: any)=> ( - {}}> + { + navigation.push('detail', {index: data.index, id:data.id, type: data.type}) + }}> { prices = {data.prices} type = {data.type} image_item = {data.image_item} - addCartItemQuantityHandler = {() => {}} - removeCartItemQuantityHandler = {() => {}} + addCartItemQuantityHandler = {addCartItemQuantityHandler} + removeCartItemQuantityHandler = {removeCartItemQuantityHandler} /> ))} diff --git a/donutshop/app/screen/Favorite.tsx b/donutshop/app/screen/Favorite.tsx index ae21225..ff86115 100644 --- a/donutshop/app/screen/Favorite.tsx +++ b/donutshop/app/screen/Favorite.tsx @@ -1,10 +1,60 @@ -import { View, Text } from 'react-native' -import React from 'react' +import { View, Text, ScrollView, Image, Pressable } from 'react-native'; +import React from 'react'; +import { useStore } from '../store/store'; +import FavCard from "../components/FavCard"; + + + + +const Favorite = ({navigation}: any) => { + const FavoriteList = useStore((state: any) => state.FavoriteList); + const addToFavoriteList = useStore((state: any) => state.addToFavoriteList); + const deleteFromFavoriteList = useStore((state: any) => state.deleteFromFavoriteList); + + const ToggleFavourite = (favourite: boolean, type: string, id: string) => { + favourite ? deleteFromFavoriteList(type, id) : addToFavoriteList(type, id) + }; + + + -const Favorite = () => { return ( - - Favorite + + + + + Favorite List + {FavoriteList.length == 0 ? ( + + + Your have no favorite list! + + ):( + + {FavoriteList.map((data: any)=> ( + { + navigation.push('detail', {index: data.index, id:data.id, type: data.type}) + }}> + + + ))} + + )} + + + ) }