From e96cd4a22da480ddb0cc1a5c228733296be42c33 Mon Sep 17 00:00:00 2001 From: nomorepanic Date: Mon, 16 Sep 2024 20:41:23 +0200 Subject: [PATCH] feat: add duplicateViewItem in useScene --- src/hooks/useScene.ts | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/src/hooks/useScene.ts b/src/hooks/useScene.ts index 85795f1d..9bd3f045 100644 --- a/src/hooks/useScene.ts +++ b/src/hooks/useScene.ts @@ -129,6 +129,18 @@ export const useScene = () => { [getState, setState, currentViewId] ); + const duplicateViewItem = useCallback( + (newViewItem: ViewItem) => { + const newState = reducers.view({ + action: 'CREATE_VIEWITEM', + payload: newViewItem, + ctx: { viewId: currentViewId, state: getState() } + }); + setState(newState); + }, + [getState, setState, currentViewId] + ) + const updateViewItem = useCallback( (id: string, updates: Partial) => { const newState = reducers.view({ @@ -287,6 +299,7 @@ export const useScene = () => { updateViewItem, deleteViewItem, createConnector, + duplicateViewItem, updateConnector, deleteConnector, createTextBox,