diff --git a/src/instruments/src/EFB/Ground/Ground.tsx b/src/instruments/src/EFB/Ground/Ground.tsx index c16444af3b6..5046133e33c 100644 --- a/src/instruments/src/EFB/Ground/Ground.tsx +++ b/src/instruments/src/EFB/Ground/Ground.tsx @@ -10,6 +10,7 @@ import { BUTTON_STATE_REDUCER } from '../Store'; import { addActiveButton, removeActiveButton, setTugRequestOnly, setActiveButtons, addDisabledButton, removeDisabledButton, + setPushBackWaitTimerHandle, } from '../Store/action-creator/ground-state'; type StatefulButton = { @@ -18,11 +19,11 @@ type StatefulButton = { } export const Ground = ({ - activeButtons, disabledButtons, tugRequestOnly, - setTugRequestOnly, addActiveButton, removeActiveButton, setActiveButtons, addDisabledButton, removeDisabledButton, + activeButtons, disabledButtons, pushBackWaitTimerHandle, setPushBackWaitTimerHandle, + tugRequestOnly, setTugRequestOnly, addActiveButton, removeActiveButton, setActiveButtons, addDisabledButton, removeDisabledButton, }) => { const [jetWayActive, setJetWayActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:0', 'Percent over 100', 'K:TOGGLE_JETWAY', 'bool', 1000); - const [_rampActive, setRampActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:0', 'Percent over 100', 'K:TOGGLE_RAMPTRUCK', 'bool', 1000); + const [, setRampActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:0', 'Percent over 100', 'K:TOGGLE_RAMPTRUCK', 'bool', 1000); const [cargoActive, setCargoActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:5', 'Percent over 100', 'K:REQUEST_LUGGAGE', 'bool', 1000); const [cateringActive, setCateringActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:3', 'Percent over 100', 'K:REQUEST_CATERING', 'bool', 1000); @@ -31,7 +32,7 @@ export const Ground = ({ const [pushBack, setPushBack] = useSplitSimVar('PUSHBACK STATE', 'enum', 'K:TOGGLE_PUSHBACK', 'bool', 1000); const [powerActive, setPowerActive] = useSplitSimVar('A:INTERACTIVE POINT OPEN:8', 'Percent over 100', 'K:REQUEST_POWER_SUPPLY', 'bool', 1000); - const [pushBackWait, setPushBackWait] = useSimVar('Pushback Wait', 'bool', 100); + const [, setPushBackWait] = useSimVar('Pushback Wait', 'bool', 100); const [pushBackAttached] = useSimVar('Pushback Attached', 'bool', 1000); const [tugDirection, setTugDirection] = useState(0); @@ -51,16 +52,19 @@ export const Ground = ({ computeAndSetTugHeading(tugDirection); setTugDirection(0); } - /** - * Timer needed, as we cannot check when the variable "Pushback Wait" is being set to false after calling the tug - */ - const timer = setInterval(() => { - if (tugRequestOnly) { - setPushBackWait(1); + if (activeButtons.find((button) => button.id === 'tug-request') && tugRequestOnly) { + /* Timer needed, as we cannot check when the variable "Pushback Wait" is being set to false after calling the tug */ + if (pushBackWaitTimerHandle === -1) { + const timer = setInterval(() => { + setPushBackWait(1); + }, 100); + setPushBackWaitTimerHandle(timer); } - }, 100); - return () => clearInterval(timer); - }, [pushBackWait, tugRequestOnly, pushBack, tugDirection]); + } else if (pushBackWaitTimerHandle !== -1) { + clearInterval(pushBackWaitTimerHandle); + setPushBackWaitTimerHandle(-1); + } + }, [pushBack, tugDirection, activeButtons, pushBackWaitTimerHandle, tugRequestOnly, pushBack, tugDirection]); const getTugHeading = (value: number): number => (tugHeading + value) % 360; @@ -316,6 +320,6 @@ export const Ground = ({ }; export default connect( - ({ [BUTTON_STATE_REDUCER]: { activeButtons, disabledButtons, tugRequestOnly } }) => ({ activeButtons, disabledButtons, tugRequestOnly }), - { addActiveButton, removeActiveButton, setActiveButtons, addDisabledButton, removeDisabledButton, setTugRequestOnly }, + ({ [BUTTON_STATE_REDUCER]: { activeButtons, disabledButtons, tugRequestOnly, pushBackWaitTimerHandle } }) => ({ activeButtons, disabledButtons, tugRequestOnly, pushBackWaitTimerHandle }), + { addActiveButton, removeActiveButton, setActiveButtons, addDisabledButton, removeDisabledButton, setTugRequestOnly, setPushBackWaitTimerHandle }, )(Ground); diff --git a/src/instruments/src/EFB/Store/action-creator/ground-state.tsx b/src/instruments/src/EFB/Store/action-creator/ground-state.tsx index 318f5c993d6..76a69bef68d 100644 --- a/src/instruments/src/EFB/Store/action-creator/ground-state.tsx +++ b/src/instruments/src/EFB/Store/action-creator/ground-state.tsx @@ -1,4 +1,4 @@ -import { ADD_ACTIVE_BUTTON, ADD_DISABLED_BUTTON, REMOVE_ACTIVE_BUTTON, REMOVE_DISABLED_BUTTON, SET_ACTIVE_BUTTONS, SET_TUG_REQUEST_ONLY } from '../actions'; +import { ADD_ACTIVE_BUTTON, ADD_DISABLED_BUTTON, REMOVE_ACTIVE_BUTTON, REMOVE_DISABLED_BUTTON, SET_ACTIVE_BUTTONS, SET_TUG_REQUEST_ONLY, SET_PUSH_BACK_WAIT_TIMER_HANDLE } from '../actions'; export const addActiveButton = (button) => ({ type: ADD_ACTIVE_BUTTON, @@ -29,3 +29,8 @@ export const setTugRequestOnly = (tugRequest) => ({ type: SET_TUG_REQUEST_ONLY, tugRequest, }); + +export const setPushBackWaitTimerHandle = (pushBackWaitTimerHandle) => ({ + type: SET_PUSH_BACK_WAIT_TIMER_HANDLE, + pushBackWaitTimerHandle, +}); diff --git a/src/instruments/src/EFB/Store/actions.ts b/src/instruments/src/EFB/Store/actions.ts index c0d1a838ce6..51d22bf36ac 100644 --- a/src/instruments/src/EFB/Store/actions.ts +++ b/src/instruments/src/EFB/Store/actions.ts @@ -14,3 +14,4 @@ export const ADD_DISABLED_BUTTON = 'ADD_DISABLED_BUTTON'; export const REMOVE_DISABLED_BUTTON = 'REMOVE_DISABLED_BUTTON'; export const SET_TUG_REQUEST_ONLY = 'SET_TUG_REQUEST_ONLY'; +export const SET_PUSH_BACK_WAIT_TIMER_HANDLE = 'SET_PUSH_BACK_WAIT_TIMER_HANDLE'; diff --git a/src/instruments/src/EFB/Store/reducer/ground-reducer.tsx b/src/instruments/src/EFB/Store/reducer/ground-reducer.tsx index 15ac88de578..88a8056f064 100644 --- a/src/instruments/src/EFB/Store/reducer/ground-reducer.tsx +++ b/src/instruments/src/EFB/Store/reducer/ground-reducer.tsx @@ -6,19 +6,21 @@ import { SET_ACTIVE_BUTTONS, REMOVE_DISABLED_BUTTON, SET_TUG_REQUEST_ONLY, + SET_PUSH_BACK_WAIT_TIMER_HANDLE, } from '../actions'; type ButtonSelectionState = { activeButtons: any[]; disabledButtons: string[]; - tugRequestOnly: boolean, - + tugRequestOnly: boolean; + pushBackWaitTimerHandle: number; }; const initialState: ButtonSelectionState = { activeButtons: [], disabledButtons: [], tugRequestOnly: false, + pushBackWaitTimerHandle: -1, }; export const buttonsReducer = typeToReducer( @@ -60,6 +62,10 @@ export const buttonsReducer = typeToReducer( ...state, tugRequestOnly: tugRequest, }), + [SET_PUSH_BACK_WAIT_TIMER_HANDLE]: (state, { pushBackWaitTimerHandle }) => ({ + ...state, + pushBackWaitTimerHandle, + }), }, initialState, ); diff --git a/src/instruments/src/EFB/rollup.development.config.js b/src/instruments/src/EFB/rollup.development.config.js index 788b9ee9b1e..e60dcd69d91 100644 --- a/src/instruments/src/EFB/rollup.development.config.js +++ b/src/instruments/src/EFB/rollup.development.config.js @@ -59,5 +59,6 @@ module.exports = { output: { file: `${__dirname}/web/bundle.js`, format: 'iife', + sourcemap: true, }, };