From 71b69c1010fd69d28dfa6b1915fb1bfa2d1be9b3 Mon Sep 17 00:00:00 2001 From: Johannes Kirschbauer Date: Sat, 19 Jul 2025 18:17:38 +0200 Subject: [PATCH] ui/scene: add promise based create machine callback" --- pkgs/clan-app/ui/src/scene/cubes.tsx | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/pkgs/clan-app/ui/src/scene/cubes.tsx b/pkgs/clan-app/ui/src/scene/cubes.tsx index a81431e4b..cc80dfaab 100644 --- a/pkgs/clan-app/ui/src/scene/cubes.tsx +++ b/pkgs/clan-app/ui/src/scene/cubes.tsx @@ -66,7 +66,7 @@ function keyFromPos(pos: [number, number]): string { export function CubeScene(props: { cubesQuery: MachinesQueryResult; - onCreate?: (id: string) => Promise; + onCreate: () => Promise<{ id: string }>; sceneStore: Accessor; setMachinePos: (machineId: string, pos: [number, number]) => void; isLoading: boolean; @@ -635,14 +635,25 @@ export function CubeScene(props: { // - Creates a new cube in "create" mode const onClick = (event: MouseEvent) => { if (worldMode() === "create") { - setWorldMode("view"); + props + .onCreate() + .then(({ id }) => { + //Successfully created machine + const pos = cursorPosition(); + if (!pos) { + console.warn("No position set for new cube"); + return; + } + props.setMachinePos(id, pos); + }) + .catch((error) => { + console.error("Error creating cube:", error); + }) + .finally(() => { + if (initBase) initBase.visible = false; - // res.result.then(() => { - // props.cubesQuery.refetch(); - - // positionMap.set("sara", pos); - // addCube("sara"); - // }); + setWorldMode("view"); + }); } const rect = renderer.domElement.getBoundingClientRect();