41 lines
1.5 KiB
TypeScript
41 lines
1.5 KiB
TypeScript
import { useCallback } from "react";
|
|
import { useMaterialStore } from "../../../../../store/simulation/useMaterialStore";
|
|
import { useArmBotStore } from "../../../../../store/simulation/useArmBotStore";
|
|
import { useProductStore } from "../../../../../store/simulation/useProductStore";
|
|
import { useSelectedProduct } from "../../../../../store/simulation/useSimulationStore";
|
|
|
|
export function usePickAndPlaceHandler() {
|
|
const { getMaterialById } = useMaterialStore();
|
|
const { addCurrentAction } = useArmBotStore();
|
|
const { getModelUuidByActionUuid } = useProductStore();
|
|
const { selectedProduct } = useSelectedProduct();
|
|
|
|
const pickAndPlaceLogStatus = (materialUuid: string, status: string) => {
|
|
// console.log(`${materialUuid}, ${status}`);
|
|
}
|
|
|
|
const handlePickAndPlace = useCallback((action: RoboticArmAction, materialId?: string) => {
|
|
if (!action || action.actionType !== 'pickAndPlace' || !materialId) return;
|
|
|
|
const material = getMaterialById(materialId);
|
|
if (!material) return;
|
|
|
|
const modelUuid = getModelUuidByActionUuid(selectedProduct.productId, action.actionUuid);
|
|
|
|
if (!modelUuid) return;
|
|
|
|
addCurrentAction(
|
|
modelUuid,
|
|
action.actionUuid,
|
|
material.materialType,
|
|
material.materialId
|
|
);
|
|
|
|
pickAndPlaceLogStatus(material.materialId, `if going to be picked by armBot ${modelUuid}`);
|
|
|
|
}, [getMaterialById, getModelUuidByActionUuid, addCurrentAction]);
|
|
|
|
return {
|
|
handlePickAndPlace,
|
|
};
|
|
} |