From 9aeb58379d51b4c5fcaffada0b6a7673cf1e4dcb Mon Sep 17 00:00:00 2001 From: louiscklaw Date: Sun, 8 Jun 2025 19:08:00 +0800 Subject: [PATCH] update demo-react-travel-app, --- .../components/PlaceCard.jsx | 171 +++++++++--------- 1 file changed, 87 insertions(+), 84 deletions(-) diff --git a/03_source/mobile/src/pages/DemoReactTravelApp/components/PlaceCard.jsx b/03_source/mobile/src/pages/DemoReactTravelApp/components/PlaceCard.jsx index 1804633..0798143 100644 --- a/03_source/mobile/src/pages/DemoReactTravelApp/components/PlaceCard.jsx +++ b/03_source/mobile/src/pages/DemoReactTravelApp/components/PlaceCard.jsx @@ -1,99 +1,102 @@ -import { IonCard, IonCardHeader, IonCardTitle, IonNote, useIonToast, CreateAnimation, IonIcon } from "@ionic/react"; -import { useState } from "react"; -import { useRef } from "react"; -import { Iconly } from "react-iconly"; -import { heart, trashBin } from "ionicons/icons"; -import { addFavourite } from "../store/PlacesStore"; +import { + IonCard, + IonCardHeader, + IonCardTitle, + IonNote, + useIonToast, + CreateAnimation, + IonIcon, +} from '@ionic/react'; +import { useState } from 'react'; +import { useRef } from 'react'; +import { Iconly } from 'react-iconly'; +import { heart, trashBin } from 'ionicons/icons'; +import { addFavourite } from '../store/PlacesStore'; -import styles from "../styles/Home.module.scss"; +import styles from '../styles/Home.module.scss'; const PlaceCard = ({ place = false, fromFavourites = false }) => { + const animationRef = useRef(null); + const cardRef = useRef(null); + const [presentToast] = useIonToast(); + const [hideAnimatedIcon, setHideAnimatedIcon] = useState(true); - const animationRef = useRef(); - const cardRef = useRef(); - const [ presentToast ] = useIonToast(); - const [ hideAnimatedIcon, setHideAnimatedIcon ] = useState(true); + const floatStyle = { + display: hideAnimatedIcon ? 'none' : '', + position: 'absolute', + zIndex: '10', + }; - const floatStyle = { + const floatGrowAnimation = { + property: 'transform', + fromValue: 'translateY(0) scale(1)', + toValue: 'translateY(-20px) scale(2)', + }; - display: hideAnimatedIcon ? "none" : "", - position: "absolute", - zIndex: "10" - }; + const mainAnimation = { + duration: 600, + iterations: '1', + fromTo: [floatGrowAnimation], + easing: 'cubic-bezier(0.25, 0.7, 0.25, 0.7)', + }; - const floatGrowAnimation = { + const handleAddFavourite = async (e, place) => { + e.stopPropagation(); + e.preventDefault(); - property: "transform", - fromValue: "translateY(0) scale(1)", - toValue: "translateY(-20px) scale(2)" - }; + if (fromFavourites) { + // Add a fadeOut animation before removing + cardRef.current.classList.add('animate__fadeOut'); - const mainAnimation = { + setTimeout(() => { + addFavourite(place, fromFavourites); + }, 500); + } else { + addFavourite(place, fromFavourites); + } - duration: 600, - iterations: "1", - fromTo: [ floatGrowAnimation ], - easing: "cubic-bezier(0.25, 0.7, 0.25, 0.7)" - }; + presentToast({ + header: `Favourite ${fromFavourites ? 'removed' : 'added'}!`, + buttons: [ + { + text: '♡', + }, + ], + message: `${place.name} has been ${fromFavourites ? 'removed from' : 'added to'} your favourites.`, + duration: 1500, + color: 'success', + }); - const handleAddFavourite = async (e, place) => { + setHideAnimatedIcon(false); + await animationRef.current.animation.play(); + setHideAnimatedIcon(true); + }; - e.stopPropagation(); - e.preventDefault(); - - if (fromFavourites) { + return ( + +
+ + {place && ( +
handleAddFavourite(e, place)}> + - // Add a fadeOut animation before removing - cardRef.current.classList.add("animate__fadeOut"); + + + +
+ )} +
- setTimeout(() => { - addFavourite(place, fromFavourites); - }, 500); - } else { + + {place ? place.name : 'Sorry'} + {place ? place.destination : 'No results found'} + +
+ ); +}; - addFavourite(place, fromFavourites); - } - - presentToast({ - - header: `Favourite ${ fromFavourites ? "removed" : "added" }!`, - buttons: [ - { - text: "♡", - } - ], - message: `${ place.name } has been ${ fromFavourites ? "removed from" : "added to" } your favourites.`, - duration: 1500, - color: "success" - }); - - setHideAnimatedIcon(false); - await animationRef.current.animation.play(); - setHideAnimatedIcon(true); - } - - return ( - -
- - { place && -
handleAddFavourite(e, place) }> - - - - - - -
- } -
- - - { place ? place.name : "Sorry" } - { place ? place.destination : "No results found" } - -
- ); -} - -export default PlaceCard; \ No newline at end of file +export default PlaceCard;