1
- import { useMemo , useContext } from 'react'
1
+ import { useMemo } from 'react'
2
2
import {
3
3
StyleSheet ,
4
4
Text ,
@@ -7,17 +7,17 @@ import {
7
7
Image ,
8
8
TouchableOpacity
9
9
} from 'react-native'
10
+ import { useNavigation } from '@react-navigation/native'
11
+ import { NativeStackNavigationProp } from '@react-navigation/native-stack'
10
12
import Icon from 'react-native-vector-icons/FontAwesome6'
11
- import { ProductCardProps } from '@Data/types'
13
+ import { ProductCardProps , GlobalStateContextProps } from '@Data/types'
12
14
import { colors } from '@Theme/colors'
13
15
import formatUSD from '@Utils/formatPrice'
14
16
import BlobBackground from '@Assets/brand/backgroundBlob.svg'
15
- import { GlobalContext } from '@Context/GlobalState'
16
17
17
- type ShoppingCardProps = ProductCardProps & {
18
- increaseQty : ( ) => void
19
- decreaseQty : ( ) => void
20
- } & ViewProps
18
+ type ShoppingCardProps = ProductCardProps &
19
+ Pick < GlobalStateContextProps , 'decreaseQty' | 'increaseQty' > &
20
+ ViewProps
21
21
22
22
const ShoppingCard = ( {
23
23
id,
@@ -31,73 +31,81 @@ const ShoppingCard = ({
31
31
decreaseQty,
32
32
...rest
33
33
} : ShoppingCardProps ) => {
34
- const { removeFromCart } = useContext ( GlobalContext )
34
+ const navigation = useNavigation < NativeStackNavigationProp < any > > ( )
35
+
36
+ function goToDetails ( ) {
37
+ navigation . push ( 'Details' , { index } )
38
+ }
35
39
36
40
return useMemo (
37
41
( ) => (
38
- < View >
39
- < View style = { styles . container } { ...rest } >
40
- < View style = { styles . productVisual } >
41
- < BlobBackground
42
- fill = { colors [ productColors [ 0 ] . blobBg ] }
43
- style = { styles . productBlob }
44
- />
45
-
46
- < Image
47
- source = { imgUrl }
48
- style = { [
49
- styles . productImg ,
50
- { maxWidth : brand === 'Beats' ? 39 : 49 }
51
- ] }
52
- />
53
- </ View >
42
+ < View style = { styles . container } { ...rest } >
43
+ < TouchableOpacity
44
+ hitSlop = { { top : 10 , right : 10 , bottom : 10 , left : 10 } }
45
+ onPress = { goToDetails }
46
+ style = { styles . productVisual }
47
+ >
48
+ < BlobBackground
49
+ fill = { colors [ productColors [ 0 ] . blobBg ] }
50
+ style = { styles . productBlob }
51
+ />
54
52
55
- < View style = { styles . productInfo } >
56
- < View style = { styles . productNamePrice } >
57
- < Text
58
- style = { styles . productName }
59
- numberOfLines = { 1 }
60
- ellipsizeMode = "clip"
61
- >
62
- { name }
63
- </ Text >
53
+ < Image
54
+ source = { imgUrl }
55
+ style = { [
56
+ styles . productImg ,
57
+ { maxWidth : brand === 'Beats' ? 39 : 49 }
58
+ ] }
59
+ />
60
+ </ TouchableOpacity >
64
61
65
- < Text
66
- style = { styles . productPrice }
67
- numberOfLines = { 1 }
68
- ellipsizeMode = "clip"
69
- >
70
- { formatUSD ( productColors [ 0 ] . price ) }
71
- </ Text >
72
- </ View >
62
+ < View style = { styles . productInfo } >
63
+ < View style = { styles . productNamePrice } >
64
+ < Text
65
+ style = { styles . productName }
66
+ numberOfLines = { 1 }
67
+ ellipsizeMode = "clip"
68
+ >
69
+ { name }
70
+ </ Text >
73
71
74
- < Text style = { styles . productDescription } numberOfLines = { 1 } >
75
- { description }
72
+ < Text
73
+ style = { styles . productPrice }
74
+ numberOfLines = { 1 }
75
+ ellipsizeMode = "clip"
76
+ >
77
+ { formatUSD ( productColors [ 0 ] . price ) }
76
78
</ Text >
77
79
</ View >
78
80
79
- < View style = { styles . actionBtns } >
80
- < TouchableOpacity
81
- hitSlop = { { top : 10 , right : 10 , bottom : 10 , left : 10 } }
82
- onPress = { increaseQty }
83
- style = { styles . actionBtn }
84
- >
85
- < Icon name = "plus" size = { 13 } color = { colors . txtDarkColor } />
86
- </ TouchableOpacity >
81
+ < View style = { styles . productDescription } >
82
+ < Text style = { styles . productColorQty } >
83
+ Color: { productColors [ 0 ] . color }
84
+ </ Text >
87
85
88
- < TouchableOpacity
89
- hitSlop = { { top : 10 , right : 10 , bottom : 10 , left : 10 } }
90
- onPress = { decreaseQty }
91
- style = { styles . actionBtn }
92
- >
93
- < Icon name = "minus" size = { 13 } color = { colors . txtDarkColor } />
94
- </ TouchableOpacity >
86
+ < Text style = { styles . productColorQty } >
87
+ Quantity: { productColors [ 0 ] . quantity }
88
+ </ Text >
95
89
</ View >
96
90
</ View >
97
91
98
- < TouchableOpacity onPress = { ( ) => removeFromCart ( id ) } >
99
- < Text style = { styles . deleteFromCarBtn } > Remove from Cart</ Text >
100
- </ TouchableOpacity >
92
+ < View style = { styles . actionBtns } >
93
+ < TouchableOpacity
94
+ hitSlop = { { top : 10 , right : 10 , bottom : 10 , left : 10 } }
95
+ onPress = { ( ) => increaseQty ( id , productColors [ 0 ] . color ) }
96
+ style = { styles . actionBtn }
97
+ >
98
+ < Icon name = "plus" size = { 13 } color = { colors . txtDarkColor } />
99
+ </ TouchableOpacity >
100
+
101
+ < TouchableOpacity
102
+ hitSlop = { { top : 10 , right : 10 , bottom : 10 , left : 10 } }
103
+ onPress = { ( ) => decreaseQty ( id , productColors [ 0 ] . color ) }
104
+ style = { styles . actionBtn }
105
+ >
106
+ < Icon name = "minus" size = { 13 } color = { colors . txtDarkColor } />
107
+ </ TouchableOpacity >
108
+ </ View >
101
109
</ View >
102
110
) ,
103
111
[
@@ -164,6 +172,10 @@ const styles = StyleSheet.create({
164
172
color : colors . primaryColor
165
173
} ,
166
174
productDescription : {
175
+ flexDirection : 'row' ,
176
+ justifyContent : 'space-between'
177
+ } ,
178
+ productColorQty : {
167
179
fontSize : 10 ,
168
180
fontWeight : '400' ,
169
181
fontFamily : 'Poppins_400Regular' ,
@@ -182,15 +194,6 @@ const styles = StyleSheet.create({
182
194
backgroundColor : colors . containerColor ,
183
195
alignItems : 'center' ,
184
196
justifyContent : 'center'
185
- } ,
186
- deleteFromCarBtn : {
187
- fontSize : 10 ,
188
- marginTop : 8 ,
189
- marginRight : 8 ,
190
- textAlign : 'right' ,
191
- fontWeight : '600' ,
192
- fontFamily : 'Poppins_600SemiBold' ,
193
- color : colors . txtDarkColor
194
197
}
195
198
} )
196
199
0 commit comments