Skip to content

Commit a483ea7

Browse files
committed
chore: refactor toolbar
1 parent 89b7f63 commit a483ea7

File tree

2 files changed

+52
-45
lines changed

2 files changed

+52
-45
lines changed

code/components/actions/utils/utils.ts

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
// SPDX-FileCopyrightText: 2025 2025 INDUSTRIA DE DISEÑO TEXTIL S.A. (INDITEX S.A.)
2+
//
3+
// SPDX-License-Identifier: Apache-2.0
4+
15
import { Weave } from "@inditextech/weave-sdk";
26
import Konva from "konva";
37
import { throttle } from "lodash";

code/components/room-components/overlay/tools-overlay.tsx

Lines changed: 48 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
//
33
// SPDX-License-Identifier: Apache-2.0
44

5-
"use client";
5+
("use client");
66

77
import React from "react";
88
import { Vector2d } from "konva/lib/types";
@@ -194,28 +194,7 @@ export function ToolsOverlay() {
194194
className="pointer-events-none absolute left-[16px] right-[16px] bottom-[16px] flex flex-col gap-2 justify-center items-center"
195195
>
196196
<Toolbar orientation="horizontal">
197-
<ToolbarButton
198-
className="rounded-full !w-[40px]"
199-
icon={<Hand className="px-2" size={40} strokeWidth={1} />}
200-
disabled={
201-
weaveConnectionStatus !== WEAVE_STORE_CONNECTION_STATUS.CONNECTED
202-
}
203-
active={actualAction === "moveTool"}
204-
onClick={() => triggerTool("moveTool")}
205-
label={
206-
<div className="flex gap-3 justify-start items-center">
207-
<p>Move</p>
208-
<ShortcutElement
209-
shortcuts={{
210-
[SYSTEM_OS.MAC]: "M",
211-
[SYSTEM_OS.OTHER]: "M",
212-
}}
213-
/>
214-
</div>
215-
}
216-
tooltipSide="top"
217-
tooltipAlign="center"
218-
/>
197+
<MoveToolTrigger />
219198
<ToolbarDivider />
220199
<ToolbarButton
221200
className="rounded-full !w-[40px]"
@@ -298,28 +277,7 @@ export function ToolsOverlay() {
298277
className="pointer-events-none absolute left-[16px] right-[16px] bottom-[16px] flex flex-col gap-2 justify-center items-center"
299278
>
300279
<Toolbar orientation="horizontal">
301-
<ToolbarButton
302-
className="rounded-full !w-[40px]"
303-
icon={<Hand className="px-2" size={40} strokeWidth={1} />}
304-
disabled={
305-
weaveConnectionStatus !== WEAVE_STORE_CONNECTION_STATUS.CONNECTED
306-
}
307-
active={actualAction === "moveTool"}
308-
onClick={() => triggerTool("moveTool")}
309-
label={
310-
<div className="flex gap-3 justify-start items-center">
311-
<p>Move</p>
312-
<ShortcutElement
313-
shortcuts={{
314-
[SYSTEM_OS.MAC]: "M",
315-
[SYSTEM_OS.OTHER]: "M",
316-
}}
317-
/>
318-
</div>
319-
}
320-
tooltipSide="top"
321-
tooltipAlign="center"
322-
/>
280+
<MoveToolTrigger />
323281
<ToolbarButton
324282
className="rounded-full !w-[40px]"
325283
icon={<MousePointer className="px-2" size={40} strokeWidth={1} />}
@@ -727,3 +685,48 @@ export function ToolsOverlay() {
727685
</motion.div>
728686
);
729687
}
688+
689+
const MoveToolTrigger = () => {
690+
const instance = useWeave((state) => state.instance);
691+
const weaveConnectionStatus = useWeave((state) => state.connection.status);
692+
const actualAction = useWeave((state) => state.actions.actual);
693+
694+
const triggerTool = React.useCallback(
695+
(toolName: string, params?: unknown) => {
696+
if (instance && actualAction !== toolName) {
697+
instance.triggerAction(toolName, params);
698+
return;
699+
}
700+
if (instance && actualAction === toolName) {
701+
instance.cancelAction(toolName);
702+
return;
703+
}
704+
},
705+
[instance, actualAction]
706+
);
707+
708+
return (
709+
<ToolbarButton
710+
className="rounded-full !w-[40px]"
711+
icon={<Hand className="px-2" size={40} strokeWidth={1} />}
712+
disabled={
713+
weaveConnectionStatus !== WEAVE_STORE_CONNECTION_STATUS.CONNECTED
714+
}
715+
active={actualAction === "moveTool"}
716+
onClick={() => triggerTool("moveTool")}
717+
label={
718+
<div className="flex gap-3 justify-start items-center">
719+
<p>Move</p>
720+
<ShortcutElement
721+
shortcuts={{
722+
[SYSTEM_OS.MAC]: "M",
723+
[SYSTEM_OS.OTHER]: "M",
724+
}}
725+
/>
726+
</div>
727+
}
728+
tooltipSide="top"
729+
tooltipAlign="center"
730+
/>
731+
);
732+
};

0 commit comments

Comments
 (0)