Skip to content

Commit

Permalink
Fixed issue with Coords component and added copy position has mater c…
Browse files Browse the repository at this point in the history
…hest
  • Loading branch information
sefirosweb committed Mar 31, 2024
1 parent f3c8829 commit 10b89a0
Show file tree
Hide file tree
Showing 2 changed files with 37 additions and 15 deletions.
22 changes: 12 additions & 10 deletions web/src/components/Forms/Coords.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -18,20 +18,22 @@ export const Coords: React.FC<Props> = (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])


Expand Down
30 changes: 25 additions & 5 deletions web/src/pages/ConfigureBot/Chests/Chest.tsx
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -20,9 +25,12 @@ type Props = {

export const Chest: React.FC<Props> = (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<ItemOption | null>(null);
const [quantity, setQuantity] = useState("1");
const [isLoading, setIsLoading] = useState(false);

const handleInsertItemInChest = () => {
const qty = Number(quantity)
Expand Down Expand Up @@ -78,7 +86,19 @@ export const Chest: React.FC<Props> = (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 = () => {
Expand Down

0 comments on commit 10b89a0

Please sign in to comment.