ui/scene: add promise based create machine callback"
This commit is contained in:
@@ -66,7 +66,7 @@ function keyFromPos(pos: [number, number]): string {
|
|||||||
|
|
||||||
export function CubeScene(props: {
|
export function CubeScene(props: {
|
||||||
cubesQuery: MachinesQueryResult;
|
cubesQuery: MachinesQueryResult;
|
||||||
onCreate?: (id: string) => Promise<void>;
|
onCreate: () => Promise<{ id: string }>;
|
||||||
sceneStore: Accessor<SceneData>;
|
sceneStore: Accessor<SceneData>;
|
||||||
setMachinePos: (machineId: string, pos: [number, number]) => void;
|
setMachinePos: (machineId: string, pos: [number, number]) => void;
|
||||||
isLoading: boolean;
|
isLoading: boolean;
|
||||||
@@ -635,14 +635,25 @@ export function CubeScene(props: {
|
|||||||
// - Creates a new cube in "create" mode
|
// - Creates a new cube in "create" mode
|
||||||
const onClick = (event: MouseEvent) => {
|
const onClick = (event: MouseEvent) => {
|
||||||
if (worldMode() === "create") {
|
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(() => {
|
setWorldMode("view");
|
||||||
// props.cubesQuery.refetch();
|
});
|
||||||
|
|
||||||
// positionMap.set("sara", pos);
|
|
||||||
// addCube("sara");
|
|
||||||
// });
|
|
||||||
}
|
}
|
||||||
|
|
||||||
const rect = renderer.domElement.getBoundingClientRect();
|
const rect = renderer.domElement.getBoundingClientRect();
|
||||||
|
|||||||
Reference in New Issue
Block a user