From 10b89a08e08dfa66cc5a38e65a5c46407a08b619 Mon Sep 17 00:00:00 2001 From: Sefirosweb Date: Sun, 31 Mar 2024 20:56:36 +0200 Subject: [PATCH] Fixed issue with Coords component and added copy position has mater chest --- web/src/components/Forms/Coords.tsx | 22 ++++++++------- web/src/pages/ConfigureBot/Chests/Chest.tsx | 30 +++++++++++++++++---- 2 files changed, 37 insertions(+), 15 deletions(-) diff --git a/web/src/components/Forms/Coords.tsx b/web/src/components/Forms/Coords.tsx index 6570cc6..d5fb5de 100644 --- a/web/src/components/Forms/Coords.tsx +++ b/web/src/components/Forms/Coords.tsx @@ -18,20 +18,22 @@ export const Coords: React.FC = (props) => { const uuid = useMemo(() => uuidv4(), []) useEffect(() => { - const newVec3 = isNaN(parseInt(x)) || isNaN(parseInt(y)) || isNaN(parseInt(z)) ? undefined : new Vec3(parseInt(x), parseInt(y), parseInt(z)) - if (!newVec3 && !coords) return - if (coords && newVec3 && newVec3.equals(coords)) return + const validAllValues = !isNaN(parseFloat(x)) && !isNaN(parseFloat(y)) && !isNaN(parseFloat(z)) + if (!validAllValues) return + const newVec3 = new Vec3(parseFloat(x), parseFloat(y), parseFloat(z)) + if (coords && coords.x === newVec3.x && coords.y === newVec3.y && coords.z === newVec3.z) return onChange(newVec3) - }, [x, y, z, onChange]) + }, [x, y, z]) useEffect(() => { - const newVec3 = isNaN(parseInt(x)) || isNaN(parseInt(y)) || isNaN(parseInt(z)) ? undefined : new Vec3(parseInt(x), parseInt(y), parseInt(z)) - if (!newVec3 && !coords) return - if (coords && newVec3 && newVec3.equals(coords)) return - setX(coords?.x.toString() ?? '') - setY(coords?.y.toString() ?? '') - setZ(coords?.z.toString() ?? '') + const validAllValues = !isNaN(parseFloat(x)) && !isNaN(parseFloat(y)) && !isNaN(parseFloat(z)) + if (!validAllValues) return + const newVec3 = new Vec3(parseFloat(x), parseFloat(y), parseFloat(z)) + if (!coords || coords.x === newVec3.x && coords.y === newVec3.y && coords.z === newVec3.z) return + setX(coords.x.toString()) + setY(coords.y.toString()) + setZ(coords.z.toString()) }, [coords]) diff --git a/web/src/pages/ConfigureBot/Chests/Chest.tsx b/web/src/pages/ConfigureBot/Chests/Chest.tsx index 07deabf..f1ac36b 100644 --- a/web/src/pages/ConfigureBot/Chests/Chest.tsx +++ b/web/src/pages/ConfigureBot/Chests/Chest.tsx @@ -1,10 +1,15 @@ -import React, { useState } from "react"; -import { ArrowDown, ArrowUp, Coords, ItemImage, ItemWithImageOption, SingleValueWithImage, Trash } from "@/components"; +import React, { useContext, useState } from "react"; import { Button, Col, Form, Row, Table } from "react-bootstrap"; -import { Chest as TypeChest, isDepositType } from "base-types"; -import { Vec3 } from "vec3"; import AsyncSelect from 'react-select/async'; +import axios from "axios"; +import { Vec3 } from "vec3"; +import toastr from 'toastr' +import { ArrowDown, ArrowUp, Coords, ItemImage, ItemWithImageOption, SingleValueWithImage, Trash } from "@/components"; +import { Chest as TypeChest, isDepositType } from "base-types"; import { ItemOption, itemOptions } from "@/lib"; +import { useStore } from "@/hooks/useStore"; +import { BotSelectedContext } from "../ConfigurationContext"; + type Props = { uuid: string @@ -20,9 +25,12 @@ type Props = { export const Chest: React.FC = (props) => { const { uuid, chest, handleMovePosNext, handleMovePosPrev, disabledMoveNext, disabledMovePrev, handleDeleteChest, handleChangeChest } = props + const { bot } = useContext(BotSelectedContext); + const [master] = useStore(state => [state.master, state.socket]) const [itemName, setItemName] = useState(null); const [quantity, setQuantity] = useState("1"); + const [isLoading, setIsLoading] = useState(false); const handleInsertItemInChest = () => { const qty = Number(quantity) @@ -78,7 +86,19 @@ export const Chest: React.FC = (props) => { } const handleCopyPositionMaster = () => { - + setIsLoading(true) + axios.get(`/api/get_master_position/${bot?.socketId}/${master}`) + .then((response) => { + const pos = new Vec3(response.data.x, response.data.y, response.data.z).floor() + console.log(pos) + handleChangeChestPos(pos) + }) + .catch((error) => { + toastr.error(error.response.data.error) + }) + .finally(() => { + setIsLoading(false) + }) }; const renderSwitch = () => {