diff --git a/package.json b/package.json index 0de6457..d9f457e 100644 --- a/package.json +++ b/package.json @@ -10,6 +10,7 @@ "preview": "vite preview" }, "dependencies": { + "@types/react-router-dom": "^5.3.3", "gsap": "^3.12.5", "react": "^18.2.0", "react-device-detect": "^2.2.3", @@ -17,7 +18,7 @@ "react-full-screen": "^1.1.1", "react-image-marker": "^1.2.0", "react-range-slider-input": "^3.0.7", - "react-router-dom": "^6.22.3", + "react-router-dom": "^6.23.1", "react-swipeable": "^7.0.1", "react-transition-group": "^4.4.5", "react-zoom-pan-pinch": "^3.4.4", diff --git a/public/images/layout-1.png b/public/images/layout-1.png new file mode 100644 index 0000000..2e9df07 Binary files /dev/null and b/public/images/layout-1.png differ diff --git a/src/calc/sortCard.ts b/src/calc/sortCard.ts new file mode 100644 index 0000000..a6d9840 --- /dev/null +++ b/src/calc/sortCard.ts @@ -0,0 +1,24 @@ +import { ILayoutCard } from "../types/layoutCard"; +import { ISort } from "../types/sortType"; + +const sortCardBy = (sortTypeList: ISort[], layoutsCards: ILayoutCard[]) => { + const sortType = sortTypeList.find((sort) => sort.isSelected); + const sortedList = [...layoutsCards].sort((cardA, cardB) => { + switch (sortType?.title) { + case "Ascending price": + return cardA.cost - cardB.cost; + case "Decreasing price": + return cardB.cost - cardA.cost; + case "Ascending Squares": + return cardA.square - cardB.square; + case "Ascending Floor": + return 1; + default: + return 1; + } + }); + + return sortedList; +}; + +export { sortCardBy }; diff --git a/src/components/Checkbox.tsx b/src/components/Checkbox.tsx index 57a1962..901d4cb 100644 --- a/src/components/Checkbox.tsx +++ b/src/components/Checkbox.tsx @@ -12,7 +12,9 @@ const Checkbox = ({ onClick, checkbox }: CheckboxProps) => {
@@ -35,7 +45,9 @@ const LayoutCard = ({ layoutCard }: LayoutCardProps) => { {units} units
+
{apartmentType}, {square} Sqft
diff --git a/src/components/searchPage/LayoutOptions.tsx b/src/components/searchPage/LayoutOptions.tsx
index 8fc8dec..824cc26 100644
--- a/src/components/searchPage/LayoutOptions.tsx
+++ b/src/components/searchPage/LayoutOptions.tsx
@@ -1,169 +1,17 @@
-import { useState } from "react";
-import { ILayoutCard } from "../../types/layoutCard";
-import { ISort } from "../../types/sortType";
+import { useEffect, useState } from "react";
import LayoutCard from "./LayoutCard";
import SortButton from "./SortButton";
-
-const layoutsCards: ILayoutCard[] = [
- {
- id: "1",
- roveHome: "Marasi Drive",
- apartmentType: "Studio Flex",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 10488888,
- square: 609,
- },
- {
- id: "2",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "3",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "4",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1138888,
- square: 609,
- },
- {
- id: "5",
- roveHome: "Marasi Drive",
- apartmentType: "Studio Flex",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 10488888,
- square: 609,
- },
- {
- id: "6",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "7",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "8",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1138888,
- square: 609,
- },
- {
- id: "9",
- roveHome: "Marasi Drive",
- apartmentType: "Studio Flex",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 10488888,
- square: 609,
- },
- {
- id: "10",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "11",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1668888,
- square: 609,
- },
- {
- id: "12",
- roveHome: "Marasi Drive",
- apartmentType: "1 Bedroom",
- wing: "East Wing",
- floorStart: 11,
- floorEnd: 35,
- units: 234,
- cost: 1138888,
- square: 609,
- },
-];
-
-const initialSortList: ISort[] = [
- {
- id: "1",
- title: "Ascending price",
- isSelected: true,
- },
- {
- id: "2",
- title: "Decreasing price",
- isSelected: false,
- },
- {
- id: "3",
- title: "Ascending Squares",
- isSelected: false,
- },
- {
- id: "4",
- title: "Ascending Floor",
- isSelected: false,
- },
-];
+import useSearchFilters from "../../store/useSearchFilters";
+import { initialSortList, layoutsCards } from "../../consts/initialSearchPage";
+import SearchIcon from "../icons/SearchIcon";
+import { sortCardBy } from "../../calc/sortCard";
const LayoutOptions = () => {
const [sortList, setSortList] = useState(initialSortList);
+ const [cards, setCards] = useState(layoutsCards);
+ const { roveHomeTypeCheckboxes, apartmentTypeCheckboxes, multirangeSliders } =
+ useSearchFilters();
+
const handleOnSortClick = (sortId: string) => {
const updatedSortList = sortList.map((sort) => {
const isSelected = sort.id === sortId;
@@ -171,20 +19,34 @@ const LayoutOptions = () => {
});
setSortList(updatedSortList);
};
+
+ useEffect(() => {
+ const sortedCards = sortCardBy(sortList, layoutsCards);
+
+ setCards(sortedCards);
+ }, [
+ sortList,
+ roveHomeTypeCheckboxes,
+ apartmentTypeCheckboxes,
+ multirangeSliders,
+ ]);
return (
145
diff --git a/src/components/searchPage/SortButton.tsx b/src/components/searchPage/SortButton.tsx
index 9400d7a..9ee53c7 100644
--- a/src/components/searchPage/SortButton.tsx
+++ b/src/components/searchPage/SortButton.tsx
@@ -21,7 +21,10 @@ const SortButton = ({ sortList, onClick }: SortButtonProps) => {
className="text-[#00BED7] text-m leading-5 flex gap-2"
onClick={handleOnClick}
>
- Sort by ascending price{" "}
+ Sort by{" "}
+
+ Rove Home Marasi Drive
+ East Wing Floor 11 № 213
+ Rove Home Marasi Drive
+
+ East Wing
+
+ Floor 11-35
+
+ AED 1668888
+ 145
+ № 213
+ Layout options
+
+ 1 bedroom apartment
+
+
+ Units
+
+ 1 bedroom apartment
+
+
+