From 4a6c068d877d9f3b0655e891c9b2281c9e11adbb Mon Sep 17 00:00:00 2001 From: Matt-Hurd Date: Sun, 17 Sep 2023 10:02:24 -0500 Subject: [PATCH] Guess layer of AddThing, open popup --- src/components/MapDisplay/ThingEditor.tsx | 6 +++- src/components/RunMosaic/AddThing.tsx | 37 ++++++++++++++++++----- 2 files changed, 34 insertions(+), 9 deletions(-) diff --git a/src/components/MapDisplay/ThingEditor.tsx b/src/components/MapDisplay/ThingEditor.tsx index 1edbce2..8f17b31 100644 --- a/src/components/MapDisplay/ThingEditor.tsx +++ b/src/components/MapDisplay/ThingEditor.tsx @@ -1,4 +1,4 @@ -import React, { useState } from "react"; +import React, { useEffect, useState } from "react"; import { Dialog, InputGroup, Button, NumericInput, Divider } from "@blueprintjs/core"; import { useDispatch } from "react-redux"; import { Thing } from "../../models"; @@ -11,6 +11,10 @@ interface ThingEditorProps { } const ThingEditor: React.FC = ({ thing, isOpen, onClose }) => { + useEffect(() => { + setEditedThing({ ...thing }); + }, [thing]); + const [editedThing, setEditedThing] = useState({ ...thing }); const dispatch = useDispatch(); diff --git a/src/components/RunMosaic/AddThing.tsx b/src/components/RunMosaic/AddThing.tsx index 5d6fb92..f8bff2d 100644 --- a/src/components/RunMosaic/AddThing.tsx +++ b/src/components/RunMosaic/AddThing.tsx @@ -2,10 +2,14 @@ import React, { useState } from "react"; import { Thing } from "../../models"; import { useDispatch } from "react-redux"; import { addThing } from "../../store/routeSlice"; +import { Dialog, Button, InputGroup } from "@blueprintjs/core"; +import ThingEditor from "../MapDisplay/ThingEditor"; export const AddThing: React.FC = () => { const [isModalOpen, setModalOpen] = useState(false); const [uid, setUid] = useState(""); + const [isEditorOpen, setIsEditorOpen] = useState(false); + const [newThing, setNewThing] = useState(null); const dispatch = useDispatch(); const handleButtonClick = () => { @@ -20,15 +24,21 @@ export const AddThing: React.FC = () => { const response = await fetch(`https://radar-totk.zeldamods.org/obj_by_hash/${uid}`); const data = await response.json(); + const adjusted_z = data.pos[1] - 105.499; + + let estimated_layer = "surface"; + if (adjusted_z < -200) estimated_layer = "depths"; + if (adjusted_z > 850) estimated_layer = "sky"; + const newThing: Thing = { uid: data.hash_id, name: data.name, coordinates: { x: -data.pos[2], y: data.pos[0], - z: data.pos[1] - 105.499, + z: adjusted_z, }, - layerId: "surface", + layerId: estimated_layer, dependencyIds: [], icon: "", type: "Thing", @@ -36,18 +46,29 @@ export const AddThing: React.FC = () => { }; dispatch(addThing(newThing)); + setNewThing(newThing); + setIsEditorOpen(true); setModalOpen(false); }; + const closeEditor = () => { + setIsEditorOpen(false); + }; + return (
- - {isModalOpen && ( -
- - + + + setModalOpen(false)}> +
+ +
+
+
- )} +
+ + {newThing && }
); };