Implement zone data management and dropdown functionality in Outline component
This commit is contained in:
@@ -1,23 +1,62 @@
|
||||
import React, { useState } from "react";
|
||||
import React, { useState, useEffect } from "react";
|
||||
import Search from "../../ui/inputs/Search";
|
||||
import DropDownList from "../../ui/list/DropDownList";
|
||||
import { useSceneContext } from "../../../modules/scene/sceneContext";
|
||||
import { isPointInsidePolygon } from "../../../functions/isPointInsidePolygon";
|
||||
|
||||
interface ZoneData {
|
||||
id: string;
|
||||
name: string;
|
||||
assets: { id: string; name: string; position?: []; rotation?: {} }[];
|
||||
}
|
||||
|
||||
const Outline: React.FC = () => {
|
||||
const [searchValue, setSearchValue] = useState<string>("");
|
||||
const [zoneDataList, setZoneDataList] = useState<ZoneData[]>([]);
|
||||
const [buildingsList, setBuildingsList] = useState<{ id: string; name: string }[]>([]);
|
||||
const [isLayersOpen, setIsLayersOpen] = useState(true);
|
||||
const [isBuildingsOpen, setIsBuildingsOpen] = useState(false);
|
||||
const [isZonesOpen, setIsZonesOpen] = useState(false);
|
||||
const { assetStore, zoneStore } = useSceneContext();
|
||||
const { assets } = assetStore();
|
||||
const { zones } = zoneStore();
|
||||
|
||||
|
||||
useEffect(() => {
|
||||
const updatedZoneList: ZoneData[] = zones?.map((zone: any) => {
|
||||
const polygon2D = zone.points.map((p: [number, number, number]) => [p[0], p[2],]);
|
||||
|
||||
const assetsInZone = assets.filter((item: any) => {
|
||||
const [x, , z] = item.position;
|
||||
return isPointInsidePolygon([x, z], polygon2D as [number, number][]);
|
||||
})
|
||||
.map((item: any) => ({
|
||||
id: item.modelUuid,
|
||||
name: item.modelName,
|
||||
position: item.position,
|
||||
rotation: item.rotation,
|
||||
}));
|
||||
|
||||
return {
|
||||
id: zone.zoneUuid,
|
||||
name: zone.zoneName,
|
||||
assets: assetsInZone,
|
||||
};
|
||||
});
|
||||
|
||||
setZoneDataList(updatedZoneList);
|
||||
}, [zones, assets]);
|
||||
|
||||
const handleSearchChange = (value: string) => {
|
||||
setSearchValue(value);
|
||||
// console.log(value); // Log the search value if needed
|
||||
};
|
||||
|
||||
const dropdownItems = [
|
||||
{ id: "1", name: "Ground Floor", active: true },
|
||||
// { id: "2", name: "Floor 1" },
|
||||
]; // Example dropdown items
|
||||
const dropdownItems = [{ id: "1", name: "Ground Floor" }];
|
||||
|
||||
return (
|
||||
<div className="outline-container">
|
||||
<Search onChange={handleSearchChange} />
|
||||
|
||||
{searchValue ? (
|
||||
<div className="searched-content">
|
||||
<p>Results for "{searchValue}"</p>
|
||||
@@ -28,7 +67,8 @@ const Outline: React.FC = () => {
|
||||
<DropDownList
|
||||
value="Layers"
|
||||
items={dropdownItems}
|
||||
defaultOpen={true}
|
||||
isOpen={isLayersOpen}
|
||||
onToggle={() => setIsLayersOpen((prev) => !prev)}
|
||||
showKebabMenu={false}
|
||||
showFocusIcon={true}
|
||||
remove
|
||||
@@ -36,10 +76,18 @@ const Outline: React.FC = () => {
|
||||
</section>
|
||||
<section className="outline-section overflow">
|
||||
<DropDownList
|
||||
value="Scene"
|
||||
items={dropdownItems}
|
||||
defaultOpen={true}
|
||||
listType="outline"
|
||||
value="Buildings"
|
||||
items={buildingsList}
|
||||
isOpen={isBuildingsOpen}
|
||||
onToggle={() => setIsBuildingsOpen((prev) => !prev)}
|
||||
showKebabMenu={false}
|
||||
showAddIcon={false}
|
||||
/>
|
||||
<DropDownList
|
||||
value="Zones"
|
||||
items={zoneDataList}
|
||||
isOpen={isZonesOpen}
|
||||
onToggle={() => setIsZonesOpen((prev) => !prev)}
|
||||
showKebabMenu={false}
|
||||
showAddIcon={false}
|
||||
/>
|
||||
|
||||
Reference in New Issue
Block a user