|
2 | 2 | // |
3 | 3 | // SPDX-License-Identifier: Apache-2.0 |
4 | 4 |
|
5 | | -"use client"; |
| 5 | +("use client"); |
6 | 6 |
|
7 | 7 | import React from "react"; |
8 | 8 | import { Vector2d } from "konva/lib/types"; |
@@ -194,28 +194,7 @@ export function ToolsOverlay() { |
194 | 194 | className="pointer-events-none absolute left-[16px] right-[16px] bottom-[16px] flex flex-col gap-2 justify-center items-center" |
195 | 195 | > |
196 | 196 | <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 /> |
219 | 198 | <ToolbarDivider /> |
220 | 199 | <ToolbarButton |
221 | 200 | className="rounded-full !w-[40px]" |
@@ -298,28 +277,7 @@ export function ToolsOverlay() { |
298 | 277 | className="pointer-events-none absolute left-[16px] right-[16px] bottom-[16px] flex flex-col gap-2 justify-center items-center" |
299 | 278 | > |
300 | 279 | <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 /> |
323 | 281 | <ToolbarButton |
324 | 282 | className="rounded-full !w-[40px]" |
325 | 283 | icon={<MousePointer className="px-2" size={40} strokeWidth={1} />} |
@@ -727,3 +685,48 @@ export function ToolsOverlay() { |
727 | 685 | </motion.div> |
728 | 686 | ); |
729 | 687 | } |
| 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