From 15f8d2e6aac46bb54277557c1a5cedf71afab731 Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sun, 8 Jun 2025 19:08:01 +0800 Subject: [PATCH] update demo-shop-app-ui, --- .../pages/DemoShopAppUi/AppPages/Category.jsx | 76 +++++++++++------- .../src/pages/DemoShopAppUi/AppPages/Home.jsx | 2 +- .../DemoShopAppUi/components/ProductModal.jsx | 79 +++++++++++-------- 3 files changed, 97 insertions(+), 60 deletions(-) diff --git a/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Category.jsx b/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Category.jsx index 18ab938..721ad47 100644 --- a/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Category.jsx +++ b/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Category.jsx @@ -1,4 +1,22 @@ -import { IonBackButton, IonBreadcrumb, IonBreadcrumbs, IonButtons, IonCol, IonContent, IonGrid, IonHeader, IonPage, IonRow, IonSearchbar, IonTitle, IonToolbar, useIonViewWillEnter, useIonViewWillLeave, IonRouterLink, useIonModal } from '@ionic/react'; +import { + IonBackButton, + IonBreadcrumb, + IonBreadcrumbs, + IonButtons, + IonCol, + IonContent, + IonGrid, + IonHeader, + IonPage, + IonRow, + IonSearchbar, + IonTitle, + IonToolbar, + useIonViewWillEnter, + useIonViewWillLeave, + IonRouterLink, + useIonModal, +} from '@ionic/react'; import { useStoreState } from 'pullstate'; import { useRef } from 'react'; import { useState } from 'react'; @@ -9,49 +27,43 @@ import { ProductStore } from '../store'; import { getCategoryProducts } from '../store/Selectors'; import { capitalizeWords } from '../utils'; -import styles from "./Category.module.scss"; +import styles from './Category.module.scss'; const Category = () => { - - const pageRef = useRef(); + const pageRef = useRef(null); const { name } = useParams(); const products = useStoreState(ProductStore, getCategoryProducts(name)); - const [ selectedProduct, setSelectedProduct ] = useState(false); - - const handleShowModal = product => { + const [selectedProduct, setSelectedProduct] = useState(false); + const handleShowModal = (product) => { setSelectedProduct(product); present({ - - cssClass: "product-modal", - presentingElement: pageRef.current + cssClass: 'product-modal', + presentingElement: pageRef.current, }); - } - - const [ present, dismiss ] = useIonModal(ProductModal, { + }; + const [present, dismiss] = useIonModal(ProductModal, { dismiss: () => dismiss(), - product: selectedProduct + product: selectedProduct, }); useIonViewWillEnter(() => { - - document.querySelector("ion-tab-bar").style.display = "none"; + document.querySelector('ion-tab-bar').style.display = 'none'; }); useIonViewWillLeave(() => { - - document.querySelector("ion-tab-bar").style.display = ""; - }) + document.querySelector('ion-tab-bar').style.display = ''; + }); return ( - + - { capitalizeWords(name) } + {capitalizeWords(name)} @@ -60,25 +72,33 @@ const Category = () => { {/* { capitalizeWords(name) } */} - Shop + + Shop + + + + {capitalizeWords(name)} - { capitalizeWords(name) } - - + - { products.map((product, index) => { - - return handleShowModal(product) } />; + {products.map((product, index) => { + return ( + handleShowModal(product)} + /> + ); })} diff --git a/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Home.jsx b/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Home.jsx index d57985c..8468409 100644 --- a/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Home.jsx +++ b/03_source/mobile/src/pages/DemoShopAppUi/AppPages/Home.jsx @@ -25,7 +25,7 @@ import { chevronBackOutline, refreshOutline } from 'ionicons/icons'; const Home = () => { const router = useIonRouter(); - const pageRef = useRef(); + const pageRef = useRef(null); const [showModal, setShowModal] = useState(false); const [selectedProduct, setSelectedProduct] = useState(false); diff --git a/03_source/mobile/src/pages/DemoShopAppUi/components/ProductModal.jsx b/03_source/mobile/src/pages/DemoShopAppUi/components/ProductModal.jsx index 5c60f22..2a49539 100644 --- a/03_source/mobile/src/pages/DemoShopAppUi/components/ProductModal.jsx +++ b/03_source/mobile/src/pages/DemoShopAppUi/components/ProductModal.jsx @@ -1,38 +1,46 @@ -import { IonBadge, IonButton, IonButtons, IonCard, IonCardContent, IonCol, IonContent, IonGrid, IonHeader, IonIcon, IonPage, IonRow, IonTitle, IonToolbar } from '@ionic/react'; +import { + IonBadge, + IonButton, + IonButtons, + IonCard, + IonCardContent, + IonCol, + IonContent, + IonGrid, + IonHeader, + IonIcon, + IonPage, + IonRow, + IonTitle, + IonToolbar, +} from '@ionic/react'; import { cart, star } from 'ionicons/icons'; import { useRef } from 'react'; import { addToCart } from '../store/CartStore'; import { capitalizeWords } from '../utils'; -import styles from "./ProductModal.module.scss"; +import styles from './ProductModal.module.scss'; export const ProductModal = ({ dismiss, product }) => { - - const cartRef = useRef(); + const cartRef = useRef(null); const handleAddToCart = () => { - - cartRef.current.style.display = "inline"; + cartRef.current.style.display = 'inline'; addToCart(product); setTimeout(() => { - - cartRef.current.style.display = "none"; + cartRef.current.style.display = 'none'; }, 750); - - } + }; return ( - View Product - - Close - + Close @@ -40,27 +48,29 @@ export const ProductModal = ({ dismiss, product }) => { - - + -
- product -
- { capitalizeWords(product.category) } -

{ product.title }

+
+ product +
+ {capitalizeWords(product.category)} +

{product.title}

-
+

Product Description

-

{ product.description }

+

{product.description}

-
+

Product Rating

-

{ product.rating.count} people have bought this item from the IonShop and have rated an average of { product.rating.rate }.

- +

+ {product.rating.count} people have bought this item from the IonShop and + have rated an average of {product.rating.rate}. +

+
@@ -69,15 +79,22 @@ export const ProductModal = ({ dismiss, product }) => { - + -
+
Buy now for - £{ product.price.toFixed(2) } + + £{product.price.toFixed(2)} +
- - Add to Cart + + Add to Cart