From 698222f0f716c8ab42db379458f4b770c6ff5f8c Mon Sep 17 00:00:00 2001 From: zojgame Date: Thu, 30 May 2024 18:36:58 +0500 Subject: [PATCH] current apartment search page --- .../searchApartment/ApartmentLayout.tsx | 10 ++- .../searchApartment/ApartmentSidebar.tsx | 87 ++++++++++--------- .../searchApartment/SimilarAppartmentCard.tsx | 2 +- .../searchApartment/SimilarSlider.tsx | 45 ++++++---- src/pages/SearchApartment.tsx | 6 +- 5 files changed, 85 insertions(+), 65 deletions(-) diff --git a/src/components/searchApartment/ApartmentLayout.tsx b/src/components/searchApartment/ApartmentLayout.tsx index f1da687..c87627f 100644 --- a/src/components/searchApartment/ApartmentLayout.tsx +++ b/src/components/searchApartment/ApartmentLayout.tsx @@ -13,9 +13,13 @@ const ApartmentLayout = () => { setCurrentLabel(label); }; return ( -
-
- +
+
+
{ return ( -
-
+
+

-

View from window

{ className="w-full h-full object-cover" />
-
-

- Parameters -

-
-
-

Complex

-

ROVE Home Marasi Drive

-
-
-

Section

-

East Wing

-
-
-

Floor

-

11

-
-
-

Number

-

213

-
-
-

Size

-

609 Sqft

+
+
+

+ Parameters +

+
+
+

Complex

+

ROVE Home Marasi Drive

+
+
+

Section

+

East Wing

+
+
+

Floor

+

11

+
+
+

Number

+

213

+
+
+

Size

+

609 Sqft

+
-
-
-

- AED 1,668,888 -

-
-
diff --git a/src/components/searchApartment/SimilarAppartmentCard.tsx b/src/components/searchApartment/SimilarAppartmentCard.tsx index b1f7f4f..d4751d7 100644 --- a/src/components/searchApartment/SimilarAppartmentCard.tsx +++ b/src/components/searchApartment/SimilarAppartmentCard.tsx @@ -27,7 +27,7 @@ const SimilarAppartmentCard = ({ layoutCard, elementRef }: LayoutCardProps) => { return (
diff --git a/src/components/searchApartment/SimilarSlider.tsx b/src/components/searchApartment/SimilarSlider.tsx index a3bdbb5..d94e156 100644 --- a/src/components/searchApartment/SimilarSlider.tsx +++ b/src/components/searchApartment/SimilarSlider.tsx @@ -1,26 +1,26 @@ +/* eslint-disable react-hooks/exhaustive-deps */ /* eslint-disable @typescript-eslint/no-unused-vars */ import { useLayoutEffect, useRef, useState } from "react"; import { layoutsCards } from "../../consts/initialSearchPage"; import SimilarAppartmentCard from "./SimilarAppartmentCard"; import Button from "../Button"; import RightArrowIcon from "../icons/RightArrowIcon"; +import { useSwipeable } from "react-swipeable"; -const cols = 4; +const desktopCols = 4; +const laptopCols = 2; const SimilarSlider = () => { const [cards, setCards] = useState(layoutsCards); const [offset, setOffset] = useState(0); const cardRef = useRef(null); const [cardWidth, setCardWidth] = useState(0); + const [cols, setCols] = useState(laptopCols); - useLayoutEffect(() => { - const cardElement = cardRef.current; - if (cardElement) { - const gap = 16; - const width = cardElement.clientWidth + gap; - setCardWidth(width); - } - }, []); + const handlers = useSwipeable({ + onSwipedLeft: () => handleOnRightBtnClick(), + onSwipedRight: () => handleOnLeftBtnClick(), + }); const handleOnLeftBtnClick = () => { if (0 > offset) { @@ -29,7 +29,7 @@ const SimilarSlider = () => { }; const handleOnRightBtnClick = () => { - if (offset > -cards.length + cols) { + if (offset > -cards.length + desktopCols) { setOffset((prev) => prev - 1); } // if (offset === -cards.length + cols) { @@ -39,13 +39,28 @@ const SimilarSlider = () => { // } }; + useLayoutEffect(() => { + const cardElement = cardRef.current; + if (cardElement) { + const gap = 16; + const width = cardElement.clientWidth + gap; + setCardWidth(width); + } + }, [window.innerWidth]); + + useLayoutEffect(() => { + const width = window.innerWidth; + const _cols = width < 1024 ? laptopCols : desktopCols; + setCols(_cols); + }, [window.innerWidth]); + return ( <>

Similar

-
+
-
-
+
+
-
+
{Array.from({ length: Math.floor(cards.length / cols) }).map( (_, index) => { return (
{cards diff --git a/src/pages/SearchApartment.tsx b/src/pages/SearchApartment.tsx index 2db4402..32f04e9 100644 --- a/src/pages/SearchApartment.tsx +++ b/src/pages/SearchApartment.tsx @@ -8,14 +8,14 @@ const SearchApartment = () => { return (
-
+
-
+
-
+