Skip to content

Commit

Permalink
Use allowMoving variable to control widgets moving
Browse files Browse the repository at this point in the history
Replaces direct usage of the `editingMode` variable, so widgets can benefit from directly controlling and overhiding the default behavior.
  • Loading branch information
rafaellehmkuhl committed Sep 18, 2023
1 parent 41e0074 commit 632d87e
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 3 deletions.
15 changes: 13 additions & 2 deletions src/stores/widgetManager.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ import { saveAs } from 'file-saver'
import { defineStore } from 'pinia'
import Swal from 'sweetalert2'
import { v4 as uuid4 } from 'uuid'
import { computed, onBeforeUnmount, ref } from 'vue'
import { computed, onBeforeUnmount, ref, watch } from 'vue'

import { widgetProfile, widgetProfiles } from '@/assets/defaults'
import { miniWidgetsProfile } from '@/assets/defaults'
Expand Down Expand Up @@ -228,7 +228,7 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => {
managerVars: {
timesMounted: 0,
configMenuOpen: false,
allowMoving: false,
allowMoving: true,
lastNonMaximizedX: 0.4,
lastNonMaximizedY: 0.32,
lastNonMaximizedWidth: 0.2,
Expand Down Expand Up @@ -293,6 +293,17 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => {
}
}

const resetWidgetsEditingState = (): void => {
currentProfile.value.views.forEach((view) => {
view.widgets.forEach((widget) => {
widget.managerVars.allowMoving = editingMode.value
})
})
}

watch(editingMode, () => resetWidgetsEditingState())
resetWidgetsEditingState()

const isFullScreen = (widget: Widget): boolean => {
return isEqual(widget.position, fullScreenPosition) && isEqual(widget.size, fullScreenSize)
}
Expand Down
2 changes: 1 addition & 1 deletion src/views/WidgetsView.vue
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<WidgetHugger
v-if="Object.values(WidgetType).includes(widget.component)"
:widget="widget"
:allow-moving="store.editingMode"
:allow-moving="widget.managerVars.allowMoving"
:allow-resizing="store.editingMode"
>
<template v-if="widget.component === WidgetType.Attitude">
Expand Down

0 comments on commit 632d87e

Please sign in to comment.