Refactor FloorPlanDubaiMarina7_38Comb component to filter duplicate units and improve mask data handling. Clean up commented code in FloorsPage and remove console logs in UnitPage for better performance.
This commit is contained in:
@@ -7,6 +7,7 @@ import { useEffect, useState } from "react";
|
||||
import clsx from "clsx";
|
||||
import { dubaiMarinaMasks } from "../data/floor-plan-masks/dubai-marina_7-38_comb";
|
||||
import { FloorPlanDubaiMarina7_38Unit } from "./FloorPlanDubaiMarina7_38";
|
||||
import { filterDuplicateUnits } from "../utils/filterDuplicateUnits";
|
||||
// import Button from "./ui/Button";
|
||||
// import { useClickAway } from "@uidotdev/usehooks";
|
||||
|
||||
@@ -62,39 +63,42 @@ function FloorPlanDubaiMarina7_38Comb({
|
||||
)
|
||||
)} */}
|
||||
|
||||
{unitsOnFloor.map((unit) =>
|
||||
!unit.unitNo.endsWith("-C") ? (
|
||||
{filterDuplicateUnits(unitsOnFloor).map((unit) => {
|
||||
// Получаем ключ для поиска в масках: для "2901-C" и "2901" это будет "01"
|
||||
const maskKey = unit.unitNo.split("-")[0].slice(-2);
|
||||
const maskData = dubaiMarinaMasks.get(maskKey);
|
||||
|
||||
if (!maskData) {
|
||||
console.warn(
|
||||
`Mask not found for unit ${unit.unitNo}, key: ${maskKey}`
|
||||
);
|
||||
return null;
|
||||
}
|
||||
|
||||
return !unit.unitNo.endsWith("-C") ? (
|
||||
<FloorPlanDubaiMarina7_38Unit
|
||||
key={unit.unitNo}
|
||||
selectedUnit={selectedUnit}
|
||||
onSelect={setSelectedUnit}
|
||||
formattedUnitType={
|
||||
dubaiMarinaMasks.get(unit.unitNo.slice(-2))!.formattedUnitType
|
||||
}
|
||||
formattedUnitType={maskData.formattedUnitType}
|
||||
unit={unit}
|
||||
floor={Number(selectedFloor!)}
|
||||
d={dubaiMarinaMasks.get(unit.unitNo.slice(-2))!.d}
|
||||
textTransform={`translate(${dubaiMarinaMasks
|
||||
.get(unit.unitNo.slice(-2))!
|
||||
.textTransform.join(" ")})`}
|
||||
d={maskData.d}
|
||||
textTransform={`translate(${maskData.textTransform.join(" ")})`}
|
||||
/>
|
||||
) : (
|
||||
<FloorPlanDubaiMarina7_38CombUnit
|
||||
key={unit.unitNo}
|
||||
selectedUnit={selectedUnit}
|
||||
onSelect={setSelectedUnit}
|
||||
formattedUnitType={
|
||||
dubaiMarinaMasks.get(unit.unitNo.slice(-2))!.formattedUnitType
|
||||
}
|
||||
formattedUnitType={maskData.formattedUnitType}
|
||||
unit={unit}
|
||||
floor={Number(selectedFloor!)}
|
||||
d={dubaiMarinaMasks.get(unit.unitNo.slice(-2))!.d}
|
||||
textTransform={`translate(${dubaiMarinaMasks
|
||||
.get(unit.unitNo.slice(-2))!
|
||||
.textTransform.join(" ")})`}
|
||||
d={maskData.d}
|
||||
textTransform={`translate(${maskData.textTransform.join(" ")})`}
|
||||
/>
|
||||
)
|
||||
)}
|
||||
);
|
||||
})}
|
||||
</svg>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -165,7 +165,7 @@ function FloorsPage() {
|
||||
/>
|
||||
</div>
|
||||
</div>
|
||||
{/* <div className="flex items-center justify-center gap-2">
|
||||
<div className="flex items-center justify-center gap-2">
|
||||
<Button
|
||||
variant={!isCombinable ? "cta" : "primary"}
|
||||
className="w-full"
|
||||
@@ -180,7 +180,7 @@ function FloorsPage() {
|
||||
>
|
||||
Combinable
|
||||
</Button>
|
||||
</div> */}
|
||||
</div>
|
||||
<div
|
||||
className="2xl:py-[1.667vw] 2xl:px-[1.111vw] max-2xl:p-4 bg-[#F3F3F2] 2xl:rounded-[0.833vw] rounded-lg relative 2xl:space-y-[2.222vw] space-y-8"
|
||||
onMouseMove={(e) =>
|
||||
|
||||
@@ -58,12 +58,6 @@ function UnitPage() {
|
||||
|
||||
setUnitTypeVariantMarasiDrive(unitTypeVariantMarasiDrive);
|
||||
}
|
||||
|
||||
if (unit) {
|
||||
console.log("Unit number:", unit.unitNo);
|
||||
console.log("Is combinable:", isUnitCombinable(unit));
|
||||
console.log("Unit type:", unit.unitType);
|
||||
}
|
||||
}, [unit]);
|
||||
|
||||
const { favoriteUnits, setFavoriteUnits } = useFavoritesUnitsStore();
|
||||
|
||||
@@ -0,0 +1,33 @@
|
||||
import { Unit } from "../types/IUnit";
|
||||
|
||||
/**
|
||||
* Фильтрует массив квартир, удаляя дубликаты без "-C" если есть версия с "-C"
|
||||
* Например: если есть и "2901" и "2901-C", то "2901" будет удален
|
||||
*
|
||||
* @param units - массив квартир для фильтрации
|
||||
* @returns отфильтрованный массив квартир
|
||||
*/
|
||||
export function filterDuplicateUnits(units: Unit[]): Unit[] {
|
||||
// Создаем Set номеров квартир с "-C" для быстрого поиска
|
||||
const unitsWithC = new Set<string>();
|
||||
|
||||
// Собираем все номера квартир с "-C"
|
||||
units.forEach(unit => {
|
||||
if (unit.unitNo.endsWith("-C")) {
|
||||
// Получаем базовый номер без "-C"
|
||||
const baseNumber = unit.unitNo.slice(0, -2);
|
||||
unitsWithC.add(baseNumber);
|
||||
}
|
||||
});
|
||||
|
||||
// Фильтруем массив: оставляем квартиры с "-C" и квартиры без "-C" только если нет дубля с "-C"
|
||||
return units.filter(unit => {
|
||||
if (unit.unitNo.endsWith("-C")) {
|
||||
// Всегда оставляем квартиры с "-C"
|
||||
return true;
|
||||
} else {
|
||||
// Оставляем квартиры без "-C" только если нет версии с "-C"
|
||||
return !unitsWithC.has(unit.unitNo);
|
||||
}
|
||||
});
|
||||
}
|
||||
Reference in New Issue
Block a user