Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion src/features/hotkeys/AppHotkeys.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@ import { openUAVDetailsDialog } from '~/features/uavs/details';
import { getSelectedUAVIds, getUAVIdList } from '~/features/uavs/selectors';
import { clearStoreAfterConfirmation } from '~/store';
import { createUAVOperationThunks } from '~/utils/messaging';
import { submitPromptDialog } from '~/features/prompt/actions';

import {
appendToPendingUAVId,
Expand Down Expand Up @@ -116,7 +117,10 @@ export default connect(
{
ACTIVATE_SELECTION: handlePendingUAVIdThenDispatch(
() => (dispatch, getState) => {
if (isKeyboardNavigationActive()) {
const state = getState();
if (state.dialogs.prompt.open) {
dispatch(submitPromptDialog({ confirmed: true }));
} else if (isKeyboardNavigationActive()) {
sendKeyboardNavigationSignal('ACTIVATE_SELECTION')();
} else {
const selectedUAVIds = getSelectedUAVIds(getState());
Expand Down
39 changes: 21 additions & 18 deletions src/utils/messaging.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ import messageHub from '~/message-hub';
import store from '~/store';

import makeLogger from './logging';
import { getUAVById } from '~/features/uavs/selectors';

const logger = makeLogger('messaging');

Expand Down Expand Up @@ -199,23 +200,6 @@ export const wakeUpUAVs = performMassOperation({
name: 'Resume from low-power mode command',
});

const moveUAVsLowLevel = performMassOperation({
type: 'UAV-FLY',
name: 'Fly to target command',
mapper: ({ target }) => ({
target: [
Math.round(target.lat * 1e7),
Math.round(target.lon * 1e7),
isNil(target.amsl) ? null : Math.round(target.amsl * 1e3),
isNil(target.ahl) ? null : Math.round(target.ahl * 1e3),
isNil(target.agl) ? null : Math.round(target.agl * 1e3),
],
}),

// Moving UAVs is such a common feature that we skip any confirmation dialogs
skipConfirmation: true,
});

export const moveUAVs = (uavIds, { target, ...rest }) => {
if (isNil(target)) {
throw new Error('No target given in arguments');
Expand All @@ -239,7 +223,26 @@ export const moveUAVs = (uavIds, { target, ...rest }) => {
args.target = { lat, lon };
}

return moveUAVsLowLevel(uavIds, args);
// Only skip confirmation if all UAVs are already in guided mode (normally due to a previous move command)
const skipConfirmation = uavIds
.map((id) => getUAVById(store.getState(), id))
.every((uav) => uav.mode === 'guided');

return performMassOperation({
type: 'UAV-FLY',
name: 'Fly to target command',
mapper: ({ target }) => ({
target: [
Math.round(target.lat * 1e7),
Math.round(target.lon * 1e7),
isNil(target.amsl) ? null : Math.round(target.amsl * 1e3),
isNil(target.ahl) ? null : Math.round(target.ahl * 1e3),
isNil(target.agl) ? null : Math.round(target.agl * 1e3),
],
}),

skipConfirmation,
})(uavIds, args);
};

export const turnMotorsOffForUAVs = performMassOperation({
Expand Down