From 084c2254eecb2c15ec686a832137e2bd48bd9c1d Mon Sep 17 00:00:00 2001 From: Faton Ramadani Date: Fri, 24 Feb 2023 18:04:31 +0100 Subject: [PATCH] fix(frontend): duplicate --- .../lib/components/apps/editor/appUtils.ts | 17 ++++++++++++ .../settingsPanel/ComponentPanel.svelte | 26 ++----------------- 2 files changed, 19 insertions(+), 24 deletions(-) diff --git a/frontend/src/lib/components/apps/editor/appUtils.ts b/frontend/src/lib/components/apps/editor/appUtils.ts index 4afe2f84aa..de65b3449f 100644 --- a/frontend/src/lib/components/apps/editor/appUtils.ts +++ b/frontend/src/lib/components/apps/editor/appUtils.ts @@ -151,3 +151,20 @@ export function deleteGridItem(app: App, id: string) { } } } + +export function duplicateGridItem( + app: App, + focusedGrid: FocusedGrid, + id: string +): string | undefined { + const gridItem = findGridItem(app, id) + if (gridItem) { + const newId = getNextGridItemId(app) + const newItem = JSON.parse(JSON.stringify(gridItem)) + newItem.id = newId + newItem.data.id = newId + + return insertNewGridItem(app, newItem.data, focusedGrid) + } + return undefined +} diff --git a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte index f080618bb9..8bb4b45eff 100644 --- a/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte +++ b/frontend/src/lib/components/apps/editor/settingsPanel/ComponentPanel.svelte @@ -21,6 +21,7 @@ import CssProperty from '../componentsPanel/CssProperty.svelte' import { dirtyStore } from '$lib/components/common/confirmationModal/dirtyStore' import GridTab from './GridTab.svelte' + import { duplicateGridItem } from '../appUtils' export let component: AppComponent | undefined export let rowColumns = false @@ -30,30 +31,7 @@ getContext('AppEditorContext') function duplicateElement(id: string) { - /* - const parent = findGridItem($app.grid, id) - - if (!parent) { - return - } - - const data: AppComponent = JSON.parse(JSON.stringify(parent.data)) - $dirtyStore = true - - const grid = $app.grid ?? [] - const newId = getNextGridItemId(grid) - - if ($focusedGrid) { - const { parentComponentId, subGridIndex } = $focusedGrid - - $app.grid = insertNewGridItem($app.grid, parentComponentId, subGridIndex, newId, data) - } else { - const newItem = createNewGridItem(grid, newId, data) - $app.grid = [...grid, newItem] - } - - $selectedComponent = newId - */ + $selectedComponent = duplicateGridItem($app, $focusedGrid, id) } function removeGridElement() {