From 8fcd72888798762e2f1a2abfad570a05892f712e Mon Sep 17 00:00:00 2001 From: sebvtl728 Date: Fri, 3 Jan 2025 01:03:52 +0100 Subject: [PATCH] add hook for devices --- .../src/components/ServicePageTemplate.jsx | 168 +++--------------- .../src/components/hooks/useIsTouchDevice.jsx | 14 ++ 2 files changed, 38 insertions(+), 144 deletions(-) create mode 100644 frontend/src/components/hooks/useIsTouchDevice.jsx diff --git a/frontend/src/components/ServicePageTemplate.jsx b/frontend/src/components/ServicePageTemplate.jsx index f7624a0..6a0faf4 100644 --- a/frontend/src/components/ServicePageTemplate.jsx +++ b/frontend/src/components/ServicePageTemplate.jsx @@ -15,6 +15,7 @@ import { Navigation, Pagination, Autoplay } from "swiper/modules"; import "swiper/css"; import "swiper/css/navigation"; import "swiper/css/pagination"; +import { useIsTouchDevice } from "./hooks/useIsTouchDevice"; // Import du hook const ServicePageTemplate = ({ title, @@ -28,6 +29,7 @@ const ServicePageTemplate = ({ }) => { const [openModal, setOpenModal] = useState(false); const [modalContent, setModalContent] = useState({}); + const isTouchDevice = useIsTouchDevice(); // Détection des écrans tactiles const handleCardClick = (feature) => { setModalContent({ @@ -66,25 +68,18 @@ const ServicePageTemplate = ({ }} > - {title} - - + {subtitle} - - ); }; -export default ServicePageTemplate; +export default ServicePageTemplate; \ No newline at end of file diff --git a/frontend/src/components/hooks/useIsTouchDevice.jsx b/frontend/src/components/hooks/useIsTouchDevice.jsx new file mode 100644 index 0000000..f900794 --- /dev/null +++ b/frontend/src/components/hooks/useIsTouchDevice.jsx @@ -0,0 +1,14 @@ +import { useEffect, useState } from "react"; + +export const useIsTouchDevice = () => { + const [isTouchDevice, setIsTouchDevice] = useState(false); + + useEffect(() => { + const checkTouchDevice = () => { + setIsTouchDevice("ontouchstart" in window || navigator.maxTouchPoints > 0); + }; + checkTouchDevice(); + }, []); + + return isTouchDevice; +}; \ No newline at end of file