From 6dea060eedd3192baa9d4c8b47b6817596782517 Mon Sep 17 00:00:00 2001 From: Juthatip McDevitt Date: Tue, 23 Jul 2024 21:37:50 -0500 Subject: [PATCH] updated donut detail page and create drink detail page with description and size functionality --- .../app/components/BackgroundDrinkInfo.tsx | 73 +++++++++++++++ donutshop/app/components/BackgroundInfo.tsx | 2 +- donutshop/app/index.js | 6 +- donutshop/app/screen/Detail.tsx | 55 +++++++----- donutshop/app/screen/DetailDrink.tsx | 90 +++++++++++++++++++ donutshop/app/screen/Menu.tsx | 4 +- 6 files changed, 205 insertions(+), 25 deletions(-) create mode 100644 donutshop/app/components/BackgroundDrinkInfo.tsx create mode 100644 donutshop/app/screen/DetailDrink.tsx diff --git a/donutshop/app/components/BackgroundDrinkInfo.tsx b/donutshop/app/components/BackgroundDrinkInfo.tsx new file mode 100644 index 0000000..fed8f81 --- /dev/null +++ b/donutshop/app/components/BackgroundDrinkInfo.tsx @@ -0,0 +1,73 @@ +import { ImageBackground, ImageProps, Pressable, StyleSheet, Text, View } from 'react-native' +import React from 'react' +import { Ionicons, AntDesign } from '@expo/vector-icons'; + +interface BackgroundDrinkInfoProps{ + EnableBackHandler: boolean; + type: string, + id: string, + image_item: ImageProps, + favourite: boolean, + name: string, + calories: string, + average_rating: number, + ratings_count: string, + BackHandler?: any; + ToggleFavorite: any +} + + +const BackgroundDrinkInfo:React.FC = ({ + EnableBackHandler, + type, + id, + image_item, + favourite, + name, + calories, + average_rating, + ratings_count, + BackHandler, + ToggleFavorite, +}) => { + + return ( + + + {EnableBackHandler ? ( + + {BackHandler()}} style={{paddingHorizontal: 10, paddingVertical: 10}}> + + + {ToggleFavorite(favourite, type, id);}} style={{paddingHorizontal: 10, paddingVertical: 10}}> + + + + ) : ( + + {ToggleFavorite(favourite, type, id);}} style={{paddingHorizontal: 10, paddingVertical: 10}}> + + + + )} + + + {name} + + + {calories} calories + + + {average_rating} + ({ratings_count}) + + + + + + ) +} + +export default BackgroundDrinkInfo + +const styles = StyleSheet.create({}) \ No newline at end of file diff --git a/donutshop/app/components/BackgroundInfo.tsx b/donutshop/app/components/BackgroundInfo.tsx index cb5e26c..3e28d50 100644 --- a/donutshop/app/components/BackgroundInfo.tsx +++ b/donutshop/app/components/BackgroundInfo.tsx @@ -62,7 +62,7 @@ const BackgroundInfo: React.FC = ({ {average_rating} - ({ratings_count}) + ({ratings_count}) diff --git a/donutshop/app/index.js b/donutshop/app/index.js index 833cd0b..05e83e2 100644 --- a/donutshop/app/index.js +++ b/donutshop/app/index.js @@ -5,8 +5,9 @@ import { createStackNavigator } from '@react-navigation/stack'; import HomeNavigator from "./navigation/HomeNavigator"; import Detail from "./screen/Detail"; import Payment from "./screen/Payment"; -import Inbox from "./screen/Inbox" -import Profile from "./screen/Profile" +import Inbox from "./screen/Inbox"; +import Profile from "./screen/Profile"; +import DetailDrink from "./screen/DetailDrink.tsx"; const Stack = createStackNavigator(); @@ -19,6 +20,7 @@ export default function Index() { + diff --git a/donutshop/app/screen/Detail.tsx b/donutshop/app/screen/Detail.tsx index 793c313..577974e 100644 --- a/donutshop/app/screen/Detail.tsx +++ b/donutshop/app/screen/Detail.tsx @@ -1,14 +1,15 @@ import { View, Text, ScrollView } from 'react-native'; -import React from 'react'; +import React, { useState } from 'react'; import { useStore } from '../store/store'; import { StatusBar } from 'expo-status-bar'; import BackgroundInfo from "../components/BackgroundInfo"; +import { TouchableWithoutFeedback } from 'react-native-gesture-handler'; const Detail = ({navigation, route}: any) => { const ItemOfIndex = useStore((state: any) => - route.params.type == 'Donut' ? state.AllDonutList1 : state.AllDrinkList, + route.params.type == 'Donut' ? state.AllDonutList1 : state.AllDrinkList1, )[route.params.index]; const addToFavoriteList = useStore((state: any) => state.addToFavoriteList); @@ -24,26 +25,40 @@ const Detail = ({navigation, route}: any) => { navigation.pop(); } + //desc + const [descriptionDrink, setDescriptionDrink] = useState(false); + return ( - - - - - - + + + + + + {descriptionDrink? ( + {setDescriptionDrink(prev => !prev)}}> + {ItemOfIndex.description} + + ) : ( + {setDescriptionDrink(prev => !prev)}}> + {ItemOfIndex.description} + + )} + + + ) } diff --git a/donutshop/app/screen/DetailDrink.tsx b/donutshop/app/screen/DetailDrink.tsx new file mode 100644 index 0000000..ea53fc8 --- /dev/null +++ b/donutshop/app/screen/DetailDrink.tsx @@ -0,0 +1,90 @@ +import { Pressable, StyleSheet, Text, View } from 'react-native' +import React, { useState } from 'react' +import { useStore } from '../store/store' +import { StatusBar } from 'expo-status-bar'; +import { ScrollView, TouchableWithoutFeedback } from 'react-native-gesture-handler'; +import BackgroundDrinkInfo from "../components/BackgroundDrinkInfo"; + + +const DetailDrink = ({navigation, route}: any) => { + const ItemOfIndex = useStore((state: any) => + route.params.type == 'Donut' ? state.AllDonutList1 : state.AllDrinkList1, + )[route.params.index]; + + const addToFavoriteList = useStore((state: any) => state.addToFavoriteList); + const deleteFromFavoriteList = useStore((state: any) => state.deleteFromFavoriteList); + + //favorite functionality + const ToggleFavorite = (favourite: boolean, type: string, id: string) => { + favourite ? deleteFromFavoriteList(type, id) : addToFavoriteList(type, id) + } + + //backhandler functionality + const BackHandler = () => { + navigation.pop(); + } + + //desc + const [descriptionDrink, setDescriptionDrink] = useState(false); + //set prices + const [price, setPrice] = useState(ItemOfIndex.prices[0]) + + return ( + + + + + + + {descriptionDrink? ( + {setDescriptionDrink(prev => !prev)}}> + {ItemOfIndex.description} + + ) : ( + {setDescriptionDrink(prev => !prev)}}> + {ItemOfIndex.description} + + )} + + + Size + + {ItemOfIndex.prices.map((data: any) => ( + + {data.size} + + ))} + + + + + + + ) +} + +export default DetailDrink + +const styles = StyleSheet.create({ + sizeBox:{ + flex: 1, + alignItems: 'center', + justifyContent: 'center', + padding: 10, + marginTop: 10, + borderRadius: 5, + borderWidth: 1 + } +}) \ No newline at end of file diff --git a/donutshop/app/screen/Menu.tsx b/donutshop/app/screen/Menu.tsx index e92a10d..8bd2729 100644 --- a/donutshop/app/screen/Menu.tsx +++ b/donutshop/app/screen/Menu.tsx @@ -33,7 +33,7 @@ const getDonutList = (category: string, data: any) => { const Menu = ({navigation}: any) => { const DonutList = useStore((state: any) => state.AllDonutList1); - const DrinkList = useStore((state: any) => state.AllDrinkList); + const DrinkList = useStore((state: any) => state.AllDrinkList1); const [categories, setCategories] = useState(getCategoriesFromData(DonutList)); const [searchMenu, setSearchMenu] = useState(''); @@ -151,7 +151,7 @@ const Menu = ({navigation}: any) => { keyExtractor={item => item.id} renderItem={({item}) => { return { - navigation.push('detail', { + navigation.push('detailDrink', { index: item.index, id: item.id, type: item.type,