Commit fce2c627 authored by Shahzad Bhatti's avatar Shahzad Bhatti

test google sign in working

parent 98f3aef8
import React from 'react'; import React from 'react';
import {View} from 'react-native'; import {StyleSheet, View} from 'react-native';
const Background = ({children}) => { const Background = ({children}) => {
return <View style={{position: 'absolute', padding: 16}}>{children}</View>; return <View style={styles.rootContainer}>{children}</View>;
}; };
const styles = StyleSheet.create({
rootContainer: {
flex: 1,
position: 'absolute',
padding: 16,
},
});
export default Background; export default Background;
import React, {useContext, useState} from 'react'; import React, {useContext, useState} from 'react';
import {View, Text, StyleSheet, Button, Image} from 'react-native'; import {View, Text, StyleSheet, Button, Image} from 'react-native';
import {Colors} from '../../constants/Constants';
import {CartContext} from '../../store/CartContext'; import {CartContext} from '../../store/CartContext';
const CartItem = ({item}) => { const CartItem = ({item}) => {
const {removeFromCart, updateQuantity} = useContext(CartContext); const {removeFromCart, updateQuantity} = useContext(CartContext);
...@@ -14,8 +14,6 @@ const CartItem = ({item}) => { ...@@ -14,8 +14,6 @@ const CartItem = ({item}) => {
updateQuantity(item.product, newQuantity); updateQuantity(item.product, newQuantity);
}; };
// setTotal(total + (item.product.price * item.quantity));
return ( return (
<View style={styles.itemContainer}> <View style={styles.itemContainer}>
<View style={styles.imageContainer}> <View style={styles.imageContainer}>
...@@ -26,13 +24,14 @@ const CartItem = ({item}) => { ...@@ -26,13 +24,14 @@ const CartItem = ({item}) => {
<Text style={styles.price}>{item.product.price}</Text> <Text style={styles.price}>{item.product.price}</Text>
</View> </View>
<View style={styles.qtyContainer}> <View style={styles.qtyContainer}>
<Button title="-" onPress={handleRemoveFromCart} /> <Button title="X" onPress={handleRemoveFromCart} />
<Button <Button
title="-" title="-"
onPress={() => handleUpdateQuantity(item.quantity - 1)} onPress={() => handleUpdateQuantity(item.quantity - 1)}
/> />
<Text>{item.product.quantity}</Text> <Text>{item.product.quantity}</Text>
<Button <Button
style={styles.inc_dec_btn}
title="+" title="+"
onPress={() => handleUpdateQuantity(item.quantity + 1)} onPress={() => handleUpdateQuantity(item.quantity + 1)}
/> />
...@@ -43,14 +42,21 @@ const CartItem = ({item}) => { ...@@ -43,14 +42,21 @@ const CartItem = ({item}) => {
const Cart = () => { const Cart = () => {
const {cart} = useContext(CartContext); const {cart} = useContext(CartContext);
const [total, setTotal] = useState(0);
const calculateTotalPrice = () => {
let total = 0;
cart.map(item => {
total += parseFloat(item.product.price) * parseInt(item.product.quantity);
});
return parseFloat(total);
};
return ( return (
<View style={styles.cartContiner}> <View style={styles.cartContiner}>
{cart.map(item => ( {cart.map(item => (
<CartItem key={item.product.id} item={item} /> <CartItem key={item.product.id} item={item} />
))} ))}
<Text style={styles.title}>Total</Text> <Text style={styles.title}>Total : {calculateTotalPrice()}</Text>
</View> </View>
); );
}; };
...@@ -101,6 +107,10 @@ const styles = StyleSheet.create({ ...@@ -101,6 +107,10 @@ const styles = StyleSheet.create({
fontSize: 14, fontSize: 14,
color: '#888', color: '#888',
}, },
inc_dec_btn: {
borderRadius: 25,
backgroundColor: Colors.primary500,
},
}); });
export default Cart; export default Cart;
import React, {useContext, useState} from 'react'; import React, {useContext, useState} from 'react';
import {View, Text, Image, Button, StyleSheet} from 'react-native'; import {View, Text, Image, Button, StyleSheet, TouchableOpacity} from 'react-native';
import {useNavigation} from '@react-navigation/native'; import {useNavigation} from '@react-navigation/native';
import {CartContext} from '../../store/CartContext'; import {CartContext} from '../../store/CartContext';
import FlatButton from '../ui/FlatButton'; import { Colors } from '../../constants/Constants';
const ProductDetail = porps => { const ProductDetail = porps => {
const item = porps.route.params.item; const item = porps.route.params.item;
...@@ -56,8 +57,12 @@ const ProductDetail = porps => { ...@@ -56,8 +57,12 @@ const ProductDetail = porps => {
flexDirection: 'row', flexDirection: 'row',
justifyContent: 'space-evenly', justifyContent: 'space-evenly',
}}> }}>
<FlatButton onPress={handleBuyNow}>Buy Now</FlatButton> <TouchableOpacity style={styles.btnBuy} onPress={handleBuyNow}>
<FlatButton onPress={handleAddToCart}>Add to Cart</FlatButton> <Text>Buy Now</Text>
</TouchableOpacity>
<TouchableOpacity onPress={handleAddToCart}>
<Text>Add to Cart</Text>
</TouchableOpacity>
</View> </View>
</View> </View>
</View> </View>
...@@ -65,11 +70,18 @@ const ProductDetail = porps => { ...@@ -65,11 +70,18 @@ const ProductDetail = porps => {
}; };
const styles = StyleSheet.create({ const styles = StyleSheet.create({
btnBuy: {
// backgroundColor: Colors.primary100,
// borderRadius: 100,
alignItems: 'center',
width: 80,
},
container: { container: {
flex: 1, flex: 1,
alignItems: 'center', alignItems: 'center',
justifyContent: 'center', justifyContent: 'center',
padding: 1, padding: 1,
background: 'linear-gradient(to bottom right, #ccc, #red)',
}, },
productContainer: { productContainer: {
flex: 1, flex: 1,
......
import React, {useContext} from 'react'; import React, {useContext} from 'react';
import {NavigationContainer} from '@react-navigation/native'; import {NavigationContainer, useNavigation} from '@react-navigation/native';
import {createNativeStackNavigator} from '@react-navigation/native-stack'; import {createNativeStackNavigator} from '@react-navigation/native-stack';
import Cart from '../components/screens/Cart'; import Cart from '../components/screens/Cart';
import MedicineList from '../components/screens/MedicineList'; import MedicineList from '../components/screens/MedicineList';
...@@ -41,12 +41,16 @@ export default function AuthStack() { ...@@ -41,12 +41,16 @@ export default function AuthStack() {
component={ProductDetail} component={ProductDetail}
options={{ options={{
title: 'Product Detail', title: 'Product Detail',
headerRight: () => ( headerRight: () => {
<Icon return (
name="shopping-cart" <Icon
size={30} onPress={authCtx.logout}
color={Colors.primary500}></Icon> // name="shopping-cart"
), name="sign-out"
size={30}
color={Colors.primary500}></Icon>
);
},
}} }}
/> />
<Stack.Screen name="Cart" component={Cart} /> <Stack.Screen name="Cart" component={Cart} />
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment