diff --git a/package-lock.json b/package-lock.json index a173543..c03084a 100644 --- a/package-lock.json +++ b/package-lock.json @@ -25,6 +25,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.11.0", + "react-intersection-observer": "^9.5.3", "react-leaflet": "^4.2.1", "react-responsive": "^9.0.2", "react-router-dom": "^6.3.0", @@ -13563,6 +13564,14 @@ "react": "*" } }, + "node_modules/react-intersection-observer": { + "version": "9.5.3", + "resolved": "https://registry.npmjs.org/react-intersection-observer/-/react-intersection-observer-9.5.3.tgz", + "integrity": "sha512-NJzagSdUPS5rPhaLsHXYeJbsvdpbJwL6yCHtMk91hc0ufQ2BnXis+0QQ9NBh6n9n+Q3OyjR6OQLShYbaNBkThQ==", + "peerDependencies": { + "react": "^15.0.0 || ^16.0.0 || ^17.0.0 || ^18.0.0" + } + }, "node_modules/react-is": { "version": "16.13.1", "resolved": "https://registry.npmjs.org/react-is/-/react-is-16.13.1.tgz", diff --git a/package.json b/package.json index fdbe25d..37388e6 100644 --- a/package.json +++ b/package.json @@ -36,6 +36,7 @@ "react": "^18.2.0", "react-dom": "^18.2.0", "react-icons": "^4.11.0", + "react-intersection-observer": "^9.5.3", "react-leaflet": "^4.2.1", "react-responsive": "^9.0.2", "react-router-dom": "^6.3.0", diff --git a/src/components/EventCard/EventCard.jsx b/src/components/EventCard/EventCard.jsx index 688f4d1..9692773 100644 --- a/src/components/EventCard/EventCard.jsx +++ b/src/components/EventCard/EventCard.jsx @@ -1,10 +1,15 @@ +import { motion, useAnimation } from "framer-motion"; import Image from "next/image"; import Link from "next/link"; -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { FaCalendarAlt } from "react-icons/fa"; +import { useInView } from "react-intersection-observer"; import Button from "../Buttons/Button"; + const EventCard = ({ t }) => { + const controls = useAnimation(); + const [ref, inView] = useInView({ triggerOnce: true }); const data = [ { id: 1, @@ -38,18 +43,33 @@ const EventCard = ({ t }) => { }, ]; const [event, setEvent] = useState(data); + useEffect(() => { + if (inView) { + controls.start({ opacity: 1, x: 0, y: 0 }); + } + }, [controls, inView]); return ( -
+

{t("Upcoming Events")}

- {event.map((event, eventIndex) => { + {event.map((event, i) => { const { id, image, title, description, date, link } = event; return ( -
+
@@ -90,7 +110,7 @@ const EventCard = ({ t }) => {
-
+ ); })}
diff --git a/src/components/EventCard/__test__/__snapshots__/EventCard.test.js.snap b/src/components/EventCard/__test__/__snapshots__/EventCard.test.js.snap index 0285588..1b58f06 100644 --- a/src/components/EventCard/__test__/__snapshots__/EventCard.test.js.snap +++ b/src/components/EventCard/__test__/__snapshots__/EventCard.test.js.snap @@ -17,6 +17,12 @@ exports[`renders correctly 1`] = ` >
{ const colRef = collection(db, "products"); const q = query(colRef, orderBy("createdAt", "desc")); @@ -21,14 +25,31 @@ export default function LatestProducts({ t }) { setProducts(latestProducts); }); }, []); + useEffect(() => { + if (inView) { + controls.start({ opacity: 1, x: 0, y: 0 }); + } + }, [controls, inView]); return ( -
+

{t("Recently Added")}

- {products?.map((product) => { - return ; + {products?.map((product, i) => { + return ( + + + + ); })}
diff --git a/src/components/ProductsList/ProductsList.jsx b/src/components/ProductsList/ProductsList.jsx index 35f7ca1..57c9f61 100644 --- a/src/components/ProductsList/ProductsList.jsx +++ b/src/components/ProductsList/ProductsList.jsx @@ -1,4 +1,6 @@ +import { motion } from "framer-motion"; import { useEffect, useState } from "react"; + import ProductCard from "../ProductCard/ProductCard"; export default function ProductsList({ products, t }) { @@ -13,13 +15,21 @@ export default function ProductsList({ products, t }) { clearTimeout(timeoutId); }; }, []); + return (
{products && products.length > 0 ? (
- {products?.map((product) => { + {products?.map((product, i) => { return ( - + + + ); })}