From 97d2ab254f14024009f76ebfa1035d4cd2dbf4b0 Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Thu, 25 Jan 2024 19:22:03 -0300 Subject: [PATCH] stores: widget-manager: Refactor `deleteMiniWidget` method to consider all available containers --- src/stores/widgetManager.ts | 16 ++++++---------- 1 file changed, 6 insertions(+), 10 deletions(-) diff --git a/src/stores/widgetManager.ts b/src/stores/widgetManager.ts index c4447f6ed..5e6a8c5b1 100644 --- a/src/stores/widgetManager.ts +++ b/src/stores/widgetManager.ts @@ -376,21 +376,17 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => { * @param { MiniWidget } miniWidget - Mini-widget */ function deleteMiniWidget(miniWidget: MiniWidget): void { - let widgetContainer: MiniWidgetContainer | undefined = undefined - - currentProfile.value.views.forEach((view) => { - const possibleContainer = view.miniWidgetContainers.find((container) => container.widgets.includes(miniWidget)) - if (possibleContainer !== undefined) widgetContainer = possibleContainer + const container: MiniWidgetContainer | undefined = miniWidgetContainersInCurrentView.value.find((cont) => { + return cont.widgets.includes(miniWidget) }) - if (widgetContainer === undefined) { - Swal.fire({ icon: 'error', text: 'Mini-widget container not found.', timer: 3000 }) + if (container === undefined) { + Swal.fire({ icon: 'error', text: 'Mini-widget container not found.' }) return } - const realContainer = widgetContainer as MiniWidgetContainer - const index = realContainer.widgets.indexOf(miniWidget) - realContainer.widgets.splice(index, 1) + const index = container.widgets.indexOf(miniWidget) + container.widgets.splice(index, 1) } /**