// RIFTR storefront — app shell wiring the views together. (() => { const { useState, useEffect } = React; function App() { const [view, setView] = useState({ name: 'home' }); const [cat, setCat] = useState('All'); const [cart, setCart] = useState([]); const [cartOpen, setCartOpen] = useState(false); const [confirm, setConfirm] = useState(false); useEffect(() => { window.lucide && window.lucide.createIcons(); }); const addToCart = (p, qty) => { setCart((c) => { const e = c.find((x) => x.id === p.id); if (e) return c.map((x) => (x.id === p.id ? { ...x, qty: x.qty + qty } : x)); return [...c, { id: p.id, name: p.name, price: p.price, img: p.img, qty }]; }); setCartOpen(true); }; const changeQty = (id, d) => setCart((c) => c.map((x) => (x.id === id ? { ...x, qty: x.qty + d } : x)).filter((x) => x.qty > 0)); const home = () => setView({ name: 'home' }); const { Header, Hero, Grid, ProductPage, Checkout, CartDrawer, Confirm, Footer } = window; return ( setCartOpen(true)} onHome={home} /> {view.name === 'home' && ( { const g = document.getElementById('grid'); if (g) window.scrollTo({ top: g.offsetTop - 70, behavior: 'smooth' }); }} onProduct={(p) => setView({ name: 'product', p })} /> setView({ name: 'product', p })} /> )} {view.name === 'product' && ( )} {view.name === 'checkout' && ( setCart([])} /> )} setCartOpen(false)} onQty={changeQty} onCheckout={() => { setCartOpen(false); setView({ name: 'checkout' }); }} /> setConfirm(false)} /> ); } ReactDOM.createRoot(document.getElementById('root')).render(); })();