Skip to content

Commit

Permalink
stores: widget-manager: Refactor deleteMiniWidget method to conside…
Browse files Browse the repository at this point in the history
…r all available containers
  • Loading branch information
rafaellehmkuhl authored and patrickelectric committed Jan 25, 2024
1 parent 759efe5 commit 97d2ab2
Showing 1 changed file with 6 additions and 10 deletions.
16 changes: 6 additions & 10 deletions src/stores/widgetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}

/**
Expand Down

0 comments on commit 97d2ab2

Please sign in to comment.