From 2ae130375a9835011082d1dca8fc3f33b4a7faed Mon Sep 17 00:00:00 2001 From: Lanskikh Date: Fri, 23 May 2025 18:30:46 +0500 Subject: [PATCH] upd --- src/components/FloorPopup.tsx | 61 +++++++++++++++------------------- src/components/FloorSelect.tsx | 43 ++++++++++++++++++------ src/stores/usePopupStore.ts | 15 +++++++++ 3 files changed, 74 insertions(+), 45 deletions(-) create mode 100644 src/stores/usePopupStore.ts diff --git a/src/components/FloorPopup.tsx b/src/components/FloorPopup.tsx index 641ebed..c6b7168 100644 --- a/src/components/FloorPopup.tsx +++ b/src/components/FloorPopup.tsx @@ -1,12 +1,15 @@ +import { formattedUnitTypes } from "../data/formattedUnitTypes"; +import { FloorsData } from "./FloorSelect"; import HumanIcon from "./icons/HumanIcon"; import { AnimatePresence, motion } from "motion/react"; interface FloorMarkerProps { title: string | null; position: [number, number]; + data: FloorsData; } -function FloorPopup({ title, position }: FloorMarkerProps) { +function FloorPopup({ title, position, data }: FloorMarkerProps) { return ( {title && ( @@ -19,7 +22,7 @@ function FloorPopup({ title, position }: FloorMarkerProps) { style={{ top: position[1], left: position[0] }} className="absolute z-100 2xl:rounded-[1.111vw] 2xl:p-[1.111vw] p-4 rounded-2xl flex flex-col 2xl:gap-[1.111vw] bg-white transition-opacity duration-300 -translate-x-[calc(100%+1.25vw)] -translate-y-1/2 2xl:w-[17.222vw] md:max-2xl:w-70 w-screen" > -
+

{Number.isNaN(+title.split(" ").at(-1)!) @@ -34,9 +37,12 @@ function FloorPopup({ title, position }: FloorMarkerProps) {

- {title && Number.isNaN((+title!.split(" ").at(-1)!)!) + {title && Number.isNaN(+title!.split(" ").at(-1)!) ? "16 Amenties" - : `8 apartments`} + : `${ + data[title.split(" ")[0] === "East" ? "east" : "west"] + .totalUnits + } apartments`}

{!Number.isNaN(+title.split(" ").at(-1)!) && (
@@ -48,39 +54,24 @@ function FloorPopup({ title, position }: FloorMarkerProps) { )}

-
+
{!Number.isNaN(+title.split(" ").at(-1)!) ? ( <> -
-

- 4 -

-

- Studio Flex -

-
-
-

- 4 -

-

Studio²

-
-
-

- 4 -

-

- 1 Bedroom² -

-
-
-

- 2 -

-

- 2 Bedroom² -

-
+ {Object.entries( + data[title.split(" ")[0] === "East" ? "east" : "west"].types + ).map(([unitType, count]) => ( +
+

+ {count} +

+

+ {formattedUnitTypes.get(unitType)} +

+
+ ))} ) : ( <> diff --git a/src/components/FloorSelect.tsx b/src/components/FloorSelect.tsx index cd84e50..7da09fa 100644 --- a/src/components/FloorSelect.tsx +++ b/src/components/FloorSelect.tsx @@ -1,4 +1,4 @@ -import { useEffect, useRef, useState } from "react"; +import { useRef, useState } from "react"; import { markers } from "../data/markers"; import { floorsMasks } from "../data/masks"; import Compass from "./Compass"; @@ -13,6 +13,18 @@ import FloorPopup from "./FloorPopup"; import { useQuery } from "@tanstack/react-query"; import { api } from "../api/ky"; +export interface FloorsData { + floor: number; + west: { + types: Record; + totalUnits: number; + }; + east: { + types: Record; + totalUnits: number; + }; +} + function FloorSelect({ complexName }: { complexName: string }) { const navigate = useNavigate(); @@ -43,14 +55,15 @@ function FloorSelect({ complexName }: { complexName: string }) { queryKey: ["floors-data", complexName], queryFn: () => api - .get(`units/get-floors-data/${complexName}`) - .json<({ floor: number } & Record)[]>(), + .get( + `units/get-floors-data/Rove Home ${complexName + .split("-") + .map((w) => w[0].toUpperCase() + w.slice(1)) + .join(" ")}` + ) + .json(), }); - useEffect(() => { - console.log(data); - }, [data]); - return (
@@ -85,7 +98,7 @@ function FloorSelect({ complexName }: { complexName: string }) {
- + {data && hoveredFloor && ( + floor === +hoveredFloor!.split(" ").at(-1)! + )! + } + /> + )}
); } diff --git a/src/stores/usePopupStore.ts b/src/stores/usePopupStore.ts new file mode 100644 index 0000000..d30f6e6 --- /dev/null +++ b/src/stores/usePopupStore.ts @@ -0,0 +1,15 @@ +import { create } from "zustand"; + +interface PopupStore { + popup: React.ReactNode | null; + setPopup: (popup: React.ReactNode) => void; + position: { x: number; y: number }; + setPosition: (position: { x: number; y: number }) => void; +} + +export const usePopupStore = create((set) => ({ + popup: null, + setPopup: (popup: React.ReactNode) => set({ popup }), + position: { x: 0, y: 0 }, + setPosition: (position: { x: number; y: number }) => set({ position }), +}));