الا
// App.js
https://www.bozy.com/self-training-ai-inside-azr-webthinker-new-chatgpt-updates/?utm_source=sapp&utm_medium=202888959&utm_campaign=313924727&utm_content=INAPP_BANNER
// React Native starter (Expo-compatible)
// شاشة بسيطة: Login, Home (قائمة متاجر), Store, Cart, Tracking
import React, { useState, useEffect, useMemo } from 'react';
import { SafeAreaView, View, Text, TextInput, TouchableOpacity, FlatList, Image, StyleSheet, Alert } from 'react-native';
import { NavigationContainer } from '@react-navigation/native';
import { createStackNavigator } from '@react-navigation/stack';
const Stack = createStackNavigator();
// --- Mock data ---
const STORES = [
{ id: 's1', name: 'مطعم البيت', subtitle: 'وجبات سريعة', img: null },
{ id: 's2', name: 'كافية المدينة', subtitle: 'قهوة ووجبات خفيفة', img: null },
{ id: 's3', name: 'بقالة الريف', subtitle: 'خضار وفواكه', img: null },
];
const PRODUCTS = {
s1: [
{ id: 'p1', name: 'برجر لحم', price: 5.5 },
{ id: 'p2', name: 'بطاطا مقلية', price: 2.0 },
],
s2: [
{ id: 'p3', name: 'كابتشينو', price: 1.8 },
{ id: 'p4', name: 'كرواسون', price: 1.2 },
],
s3: [
{ id: 'p5', name: 'تفاح (كجم)', price: 1.5 },
{ id: 'p6', name: 'موز (كجم)', price: 1.1 },
],
};
// --- Simple Cart Context (local) ---
const useCart = () => {
const [cart, setCart] = useState([]); // {product, storeId, qty}
const addToCart = (storeId, product) => {
setCart(prev => {
// if different store, replace cart (simple policy)
if (prev.length > 0 && prev[0].storeId !== storeId) {
Alert.alert('تنبيه', 'سلة الطلب تحتوي على أصناف من متجر آخر. سيتم استبدالها.');
return [{ storeId, product, qty: 1 }];
}
const found = prev.find(i => i.product.id === product.id);
if (found) return prev.map(i => i.product.id === product.id ? { ...i, qty: i.qty + 1 } : i);
return [...prev, { storeId, product, qty: 1 }];
});
};
const changeQty = (productId, delta) => {
setCart(prev => prev
.map(i => i.product.id === productId ? { ...i, qty: Math.max(0, i.qty + delta) } : i)
.filter(i => i.qty > 0)
);
};
const clear = () => setCart([]);
const total = useMemo(() => cart.reduce((s, i) => s + i.product.price * i.qty, 0), [cart]);
return { cart, addToCart, changeQty, clear, total };
};
// --- Screens ---
function LoginScreen({ navigation }) {
const [phone, setPhone] = useState('');
const onLogin = () => {
if (!phone) return Alert.alert('خطأ', 'أدخل رقم الهاتف');
// mock login
navigation.replace('Home');
};
return (
مرحبا بك في تطبيق الطلبات
تسجيل / دخول
);
}
function HomeScreen({ navigation }) {
return (
المتاجر القريبة
i.id}
renderItem={({ item }) => (
navigation.navigate('Store', { storeId: item.id, name: item.name })}>
{item.name}
{item.subtitle}
›
)}
/>
);
}
function StoreScreen({ route, navigation }) {
const { storeId, name } = route.params;
const { addToCart } = useCartRef;
const products = PRODUCTS[storeId] || [];
return (
{name}
i.id}
renderItem={({ item }) => (
{item.name}
{item.price.toFixed(2)} JD
addToCart(storeId, item)}>
أضف
)}
/>
navigation.navigate('Cart')}>
سلة
);
}
function CartScreen({ navigation }) {
const { cart, changeQty, total, clear } = useCartRef;
const onCheckout = () => {
if (cart.length === 0) return Alert.alert('السلة فارغة');
// mock order creation
clear();
navigation.replace('Tracking', { orderId: Math.random().toString(36).slice(2,8) });
};
return (
سلة الطلب
{cart.length === 0 ? (
لا توجد أصناف في السلة
) : (
i.product.id}
renderItem={({ item }) => (
{item.product.name}
{item.product.price.toFixed(2)} JD
changeQty(item.product.id, -1)} style={styles.qtyBtn}>-
{item.qty}
changeQty(item.product.id, 1)} style={styles.qtyBtn}>+
)}
/>
)}
الإجمالي: {total.toFixed(2)} JD
تأكيد الطلب
);
}
function TrackingScreen({ route }) {
const { orderId } = route.params;
// simple mock states
const [status, setStatus] = useState('جارٍ التجهيز');
useEffect(() => {
const t1 = setTimeout(() => setStatus('خرج للتوصيل'), 2500);
const t2 = setTimeout(() => setStatus('تم التسليم'), 6000);
return () => { clearTimeout(t1); clearTimeout(t2); };
}, []);
return (
تتبع الطلب #{orderId}
{status}
خريطة (تمثيل مبسط)
خريطة
);
}
// --- Simple way to share cart between screens (quick hack for starter) ---
let useCartRef = null;
function AppInner() {
const cart = useCart();
useEffect(() => { useCartRef = cart; }, [cart]);
return (
({ title: route.params.name })} />
);
}
export default function App() {
return ;
}
const styles = StyleSheet.create({
container: { flex: 1, padding: 16, backgroundColor: '#fff' },
title: { fontSize: 22, fontWeight: '700', marginBottom: 12, textAlign: 'center' },
subtitle: { fontSize: 18, fontWeight: '600', marginBottom: 8 },
input: { borderWidth: 1, borderColor: '#ddd', padding: 12, borderRadius: 8, marginBottom: 12 },
button: { backgroundColor: '#0b79f7', padding: 12, borderRadius: 8, alignItems: 'center', marginTop: 8 },
buttonText: { color: '#fff', fontWeight: '600' },
card: { flexDirection: 'row', padding: 12, borderWidth: 1, borderColor: '#eee', borderRadius: 8, marginBottom: 8, alignItems: 'center' },
cardTitle: { fontSize: 16, fontWeight: '700' },
cardSubtitle: { color: '#666' },
cardRight: { width: 24, alignItems: 'center' },
productRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 12, borderBottomWidth: 1, borderColor: '#f1f1f1' },
productName: { fontWeight: '600' },
productPrice: { color: '#333' },
addButton: { backgroundColor: '#0b79f7', padding: 8, borderRadius: 6 },
fab: { position: 'absolute', right: 16, bottom: 16, backgroundColor: '#0b79f7', padding: 12, borderRadius: 24, elevation: 3 },
cartRow: { flexDirection: 'row', justifyContent: 'space-between', alignItems: 'center', padding: 12, borderBottomWidth: 1, borderColor: '#f1f1f1' },
qtyBtn: { borderWidth: 1, borderColor: '#ddd', padding: 6, borderRadius: 6 },
cartFooter: { padding: 12, borderTopWidth: 1, borderColor: '#eee', marginTop: 8 },
mapMock: { height: 160, borderWidth: 1, borderColor: '#ddd', borderRadius: 8, marginTop: 8, alignItems: 'center', justifyContent: 'center' },
});
https://megaelectronics.bg/produkt/klimatik-mitsubishi-heavy-industries-srk35zsx-w-src35zsx-w/?gad_source=5&gad_campaignid=6731927681&gclid=EAIaIQobChMI0ZnzjvPRjwMV-3D_Ax1DwDjMEAEYASAAEgKthPD_BwE
تعليقات
إرسال تعليق