diff --git a/src/components/FloorPopup.tsx b/src/components/FloorPopup.tsx index 2b33f05..e008ddf 100644 --- a/src/components/FloorPopup.tsx +++ b/src/components/FloorPopup.tsx @@ -1,11 +1,11 @@ -import { useEffect, useMemo, useState } from "react"; +import { useMemo } from "react"; import { formattedUnitTypes } from "../data/formattedUnitTypes"; import { usePopupStore } from "../stores/usePopupStore"; -import getAmentiesCount, { AmentiesCount } from "../utils/getAmentiesCount"; import { FloorsData } from "./FloorSelect"; import ArrowRightIcon from "./icons/ArrowRightIcon"; import HumanIcon from "./icons/HumanIcon"; import Button from "./ui/Button"; +import { projects } from "../data/projects"; interface FloorPopupProps { title: string; @@ -14,28 +14,22 @@ interface FloorPopupProps { onSelect: (floor: string) => void; } +function getAmentiesCount(complexName: string, title: string) { + const amenties = projects.find( + (proj) => proj.slug === complexName + )?.amentiesFloors; + return amenties?.find((amenty) => amenty.title === title); +} + function FloorPopup({ title, complexName, data, onSelect }: FloorPopupProps) { const { setPopup } = usePopupStore(); - const initialState = useMemo( + const amentiesCount = useMemo( () => - Number.isNaN(+title.split(" ").at(-1)!) + Number.isNaN(+title.at(-1)!) ? getAmentiesCount(complexName, title) : null, [title, complexName] ); - const [amentiesCount, setAmentiesCount] = useState( - initialState - ); - - useEffect(() => { - if (Number.isNaN(+title.split(" ").at(-1)!)) { - setAmentiesCount(getAmentiesCount(complexName, title)); - } else { - setAmentiesCount(null); - } - - return () => setAmentiesCount(null); - }, [complexName, title]); return (
diff --git a/src/data/projects.ts b/src/data/projects.ts index 4142478..8c53c6f 100644 --- a/src/data/projects.ts +++ b/src/data/projects.ts @@ -525,6 +525,28 @@ export const projects: Project[] = [ tourAvailable: true, }, ], + amentiesFloors: [ + { + title: "Rooftop", + total: 10, + }, + { + title: "Sky Garden", + total: 15, + indoor: 3, + outdoor: 12, + }, + { + title: "Podium Level", + total: 27, + indoor: 13, + outdoor: 14, + }, + { + title: "Ground Level", + total: 7, + }, + ], }, { title: "Rove Home Dubai Marina", @@ -1764,5 +1786,21 @@ export const projects: Project[] = [ ], }, ], + amentiesFloors: [ + { + title: "Rooftop", + total: 14, + }, + { + title: "Podium Level", + total: 21, + indoor: 8, + outdoor: 13, + }, + { + title: "Ground Level", + total: 14, + }, + ], }, ]; diff --git a/src/pages/FloorsPage.tsx b/src/pages/FloorsPage.tsx index 029afef..cc4b7bd 100644 --- a/src/pages/FloorsPage.tsx +++ b/src/pages/FloorsPage.tsx @@ -162,7 +162,7 @@ function FloorsPage() {
!isMobile && setPosition({ x: e.clientX, y: e.clientY }) } diff --git a/src/types/Project.ts b/src/types/Project.ts index 168a0b0..a5225ed 100644 --- a/src/types/Project.ts +++ b/src/types/Project.ts @@ -5,4 +5,12 @@ export default interface Project { slug: string; img: string; types: UnitType[]; + amentiesFloors: AmentiesFloor[]; } + +export interface AmentiesFloor { + title: string; + total: number; + indoor?: number; + outdoor?: number; +} \ No newline at end of file diff --git a/src/utils/getAmentiesCount.ts b/src/utils/getAmentiesCount.ts deleted file mode 100644 index d9416ac..0000000 --- a/src/utils/getAmentiesCount.ts +++ /dev/null @@ -1,22 +0,0 @@ -export interface AmentiesCount { - total: number; - indoor?: number; - outdoor?: number; -} - -export default function getAmentiesCount( - complexName: string, - floorTitle: string -):AmentiesCount | null { - const dict = new Map([ - ["marasi-drive Rooftop", { total: 10 }], - ["marasi-drive Sky Garden", { total: 15, indoor: 3, outdoor: 12 }], - ["marasi-drive Podium Level", { total: 27, indoor: 13, outdoor: 14 }], - ["marasi-drive Ground Level", { total: 7 }], - ["dubai-marina Rooftop", { total: 14 }], - ["dubai-marina Podium Level", { total: 21, indoor: 8, outdoor: 13 }], - ["dubai-marina Ground Level", { total: 14 }], - ]); - - return dict.get(`${complexName} ${floorTitle}`) || null; -}