From be121fc2c40eeeb0fef79056528ee4cac2756fba Mon Sep 17 00:00:00 2001 From: Rafael Araujo Lehmkuhl Date: Mon, 31 Jul 2023 18:29:35 -0300 Subject: [PATCH] Add cockpit-action to change to previous view --- src/libs/joystick/protocols.ts | 1 + src/stores/widgetManager.ts | 7 +++++++ 2 files changed, 8 insertions(+) diff --git a/src/libs/joystick/protocols.ts b/src/libs/joystick/protocols.ts index 900586cf7..d6356d764 100644 --- a/src/libs/joystick/protocols.ts +++ b/src/libs/joystick/protocols.ts @@ -82,6 +82,7 @@ export class MavlinkControllerState extends ProtocolControllerState { */ export enum CockpitAction { GO_TO_NEXT_VIEW = 'Go to next view', + GO_TO_PREVIOUS_VIEW = 'Go to previous view', TOGGLE_FULL_SCREEN = 'Toggle full-screen', MAVLINK_ARM = 'Mavlink Command - Arm', MAVLINK_DISARM = 'Mavlink Command - Disarm', diff --git a/src/stores/widgetManager.ts b/src/stores/widgetManager.ts index 4c7919a6b..fe8582884 100644 --- a/src/stores/widgetManager.ts +++ b/src/stores/widgetManager.ts @@ -262,6 +262,13 @@ export const useWidgetManagerStore = defineStore('widget-manager', () => { const selectNextViewCallbackId = registerActionCallback(CockpitAction.GO_TO_NEXT_VIEW, debouncedSelectNextView) onBeforeUnmount(() => unregisterActionCallback(selectNextViewCallbackId)) + const selectPreviousView = (): void => { + const newIndex = currentViewIndex.value === 0 ? currentProfile.value.views.length - 1 : currentViewIndex.value - 1 + selectView(currentProfile.value.views[newIndex]) + } + const debouncedSelectPreviousView = useDebounceFn(() => selectPreviousView(), 500) + const selectPrevViewCBId = registerActionCallback(CockpitAction.GO_TO_PREVIOUS_VIEW, debouncedSelectPreviousView) + onBeforeUnmount(() => unregisterActionCallback(selectPrevViewCBId)) return { editingMode,