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,