|
| 1 | +import React from 'react'; |
| 2 | +import { View, Text, FlatList, Image, TouchableOpacity, StyleSheet, Dimensions } from 'react-native'; |
| 3 | +import { SafeAreaView } from 'react-native-safe-area-context'; |
| 4 | +import { Heart, Trash2 } from 'lucide-react-native'; |
| 5 | +import { colors } from '../theme/colors'; |
| 6 | +import { useApp } from '../context/AppContext'; |
| 7 | + |
| 8 | +const W = Dimensions.get('window').width; |
| 9 | + |
| 10 | +export default function WishlistScreen({ navigation }) { |
| 11 | + const { wishlistItems, toggleWishlist } = useApp(); |
| 12 | + |
| 13 | + if (wishlistItems.length === 0) { |
| 14 | + return ( |
| 15 | + <SafeAreaView style={styles.safe}> |
| 16 | + <View style={styles.topBar}> |
| 17 | + <Text style={styles.title}>MY WISHLIST</Text> |
| 18 | + </View> |
| 19 | + <View style={styles.empty}> |
| 20 | + <Heart size={56} color={colors.border} /> |
| 21 | + <Text style={styles.emptyTitle}>Your wishlist is empty</Text> |
| 22 | + <TouchableOpacity style={styles.shopBtn} onPress={() => navigation.goBack()}> |
| 23 | + <Text style={styles.shopBtnTxt}>CONTINUE SHOPPING</Text> |
| 24 | + </TouchableOpacity> |
| 25 | + </View> |
| 26 | + </SafeAreaView> |
| 27 | + ); |
| 28 | + } |
| 29 | + |
| 30 | + return ( |
| 31 | + <SafeAreaView style={styles.safe}> |
| 32 | + <View style={styles.topBar}> |
| 33 | + <Text style={styles.title}>MY WISHLIST</Text> |
| 34 | + <Text style={styles.count}>{wishlistItems.length} item{wishlistItems.length > 1 ? 's' : ''}</Text> |
| 35 | + </View> |
| 36 | + |
| 37 | + <FlatList |
| 38 | + data={wishlistItems} |
| 39 | + keyExtractor={item => item.id.toString()} |
| 40 | + contentContainerStyle={styles.list} |
| 41 | + renderItem={({ item }) => ( |
| 42 | + <TouchableOpacity |
| 43 | + style={styles.item} |
| 44 | + onPress={() => navigation.navigate('ProductDetail', { product: item })} |
| 45 | + activeOpacity={0.9} |
| 46 | + > |
| 47 | + <Image source={{ uri: item.image }} style={styles.itemImg} resizeMode="cover" /> |
| 48 | + <View style={styles.itemInfo}> |
| 49 | + <Text style={styles.itemBrand}>{item.brand}</Text> |
| 50 | + <Text style={styles.itemName} numberOfLines={2}>{item.name}</Text> |
| 51 | + <Text style={styles.itemPrice}>₹ {item.price.toLocaleString('en-IN')}</Text> |
| 52 | + </View> |
| 53 | + <TouchableOpacity style={styles.removeBtn} onPress={() => toggleWishlist(item)}> |
| 54 | + <Trash2 size={18} color={colors.gray} /> |
| 55 | + </TouchableOpacity> |
| 56 | + </TouchableOpacity> |
| 57 | + )} |
| 58 | + /> |
| 59 | + </SafeAreaView> |
| 60 | + ); |
| 61 | +} |
| 62 | + |
| 63 | +const styles = StyleSheet.create({ |
| 64 | + safe: { flex: 1, backgroundColor: colors.white }, |
| 65 | + topBar: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', paddingHorizontal: 20, paddingVertical: 14, borderBottomWidth: 1, borderBottomColor: colors.border }, |
| 66 | + title: { fontSize: 16, fontWeight: '800', letterSpacing: 1.5, color: colors.dark }, |
| 67 | + count: { fontSize: 13, color: colors.gray }, |
| 68 | + list: { padding: 16, gap: 12 }, |
| 69 | + item: { flexDirection: 'row', gap: 14, backgroundColor: colors.white, borderRadius: 14, padding: 12, shadowColor: '#000', shadowOpacity: 0.06, shadowRadius: 8, elevation: 2 }, |
| 70 | + itemImg: { width: 90, height: 90, borderRadius: 12, backgroundColor: colors.lightGray }, |
| 71 | + itemInfo: { flex: 1, justifyContent: 'center' }, |
| 72 | + itemBrand: { fontSize: 10, fontWeight: '700', color: colors.gray, letterSpacing: 1, marginBottom: 4 }, |
| 73 | + itemName: { fontSize: 14, fontWeight: '700', color: colors.dark, marginBottom: 8 }, |
| 74 | + itemPrice: { fontSize: 16, fontWeight: '800', color: colors.dark }, |
| 75 | + removeBtn: { padding: 4, alignSelf: 'center' }, |
| 76 | + empty: { flex: 1, alignItems: 'center', justifyContent: 'center', gap: 16 }, |
| 77 | + emptyTitle: { fontSize: 16, fontWeight: '700', color: colors.gray }, |
| 78 | + shopBtn: { backgroundColor: colors.brand, paddingHorizontal: 24, paddingVertical: 12, borderRadius: 10 }, |
| 79 | + shopBtnTxt: { color: colors.white, fontWeight: '700', fontSize: 13 }, |
| 80 | +}); |
0 commit comments