63 lines
1.9 KiB
TypeScript
63 lines
1.9 KiB
TypeScript
import { getUserData } from "../../../../functions/getUserData";
|
|
import * as Types from "../../../../types/world/worldTypes";
|
|
// import { deleteWallItem } from '../../../../services/factoryBuilder/assest/wallAsset/deleteWallItemApi';
|
|
import { Socket } from "socket.io-client";
|
|
|
|
function DeleteWallItems(
|
|
hoveredDeletableWallItem: Types.RefMesh,
|
|
setWallItems: Types.setWallItemSetState,
|
|
wallItems: Types.wallItems,
|
|
socket: Socket<any>,
|
|
projectId?: string,
|
|
versionId? : string,
|
|
): void {
|
|
////////// Deleting the hovered Wall GLTF from thewallItems and also update it in the localstorage //////////
|
|
const { userId, organization, email } = getUserData();
|
|
if (hoveredDeletableWallItem.current && hoveredDeletableWallItem.current) {
|
|
setWallItems([]);
|
|
let WallItemsRef = wallItems;
|
|
const removedItem = WallItemsRef.find(
|
|
(item) => item.model?.uuid === hoveredDeletableWallItem.current?.uuid
|
|
);
|
|
const Items = WallItemsRef.filter(
|
|
(item) => item.model?.uuid !== hoveredDeletableWallItem.current?.uuid
|
|
);
|
|
|
|
setTimeout(async () => {
|
|
WallItemsRef = Items;
|
|
setWallItems(WallItemsRef);
|
|
|
|
//REST
|
|
|
|
// await deleteWallItem(organization, removedItem?.model?.uuid!, removedItem?.modelName!)
|
|
|
|
//SOCKET
|
|
|
|
const data = {
|
|
organization,
|
|
modelUuid: removedItem?.model?.uuid!,
|
|
modelName: removedItem?.modelName!,
|
|
socketId: socket.id,
|
|
projectId,
|
|
versionId,
|
|
userId,
|
|
};
|
|
|
|
socket.emit("v1:wallItems:delete", data);
|
|
|
|
const WallItemsForStorage = WallItemsRef.map((item) => {
|
|
const { model, ...rest } = item;
|
|
return {
|
|
...rest,
|
|
modelUuid: model?.uuid,
|
|
};
|
|
});
|
|
|
|
localStorage.setItem("WallItems", JSON.stringify(WallItemsForStorage));
|
|
hoveredDeletableWallItem.current = null;
|
|
}, 50);
|
|
}
|
|
}
|
|
|
|
export default DeleteWallItems;
|