Skip to content

Commit

Permalink
Fix: exit before dispatch if we have a pending trigger
Browse files Browse the repository at this point in the history
  • Loading branch information
kylebonnici committed Mar 8, 2024
1 parent ad410b3 commit ae76d56
Showing 1 changed file with 23 additions and 18 deletions.
41 changes: 23 additions & 18 deletions src/actions/deviceActions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,7 @@ import {
import { updateGainsAction } from '../slices/gainsSlice';
import {
clearProgress,
getTriggerRecordingLength,
resetTriggerOrigin,
setProgress,
setTriggerActive,
Expand Down Expand Up @@ -250,20 +251,30 @@ export const open =
const validTriggerValue =
cappedValue >= getState().app.trigger.level;
if (!getState().app.trigger.active && validTriggerValue) {
if (latestTrigger !== undefined) {
return;
}

if (!isSavePending(getState())) {
dispatch(setSavePending(true));
}
dispatch(setTriggerActive(true));
dispatch(
processTrigger(cappedValue, (progressMessage, prog) => {
dispatch(
setProgress({
progressMessage,
progress:
prog && prog >= 0 ? prog : undefined,
})
);
})
processTrigger(
cappedValue,
getTriggerRecordingLength(getState()) * 1000, // ms to uS
(progressMessage, prog) => {
dispatch(
setProgress({
progressMessage,
progress:
prog && prog >= 0
? prog
: undefined,
})
);
}
)
).then(() => {
if (!DataManager().hasPendingTriggers()) {
dispatch(clearProgress());
Expand Down Expand Up @@ -473,6 +484,7 @@ let releaseLastSession: (() => void) | undefined;
export const processTrigger =
(
triggerValue: number,
triggerLength: number,
onProgress?: (message: string, progress?: number) => void
): AppThunk<RootState, Promise<void>> =>
async (dispatch, getState) => {
Expand All @@ -481,17 +493,10 @@ export const processTrigger =
return;
}

if (latestTrigger !== undefined) {
return;
}

const trigger = DataManager().addTimeReachedTrigger(
getState().app.trigger.recordingLength * 1000 // ms to uS
);
const trigger = DataManager().addTimeReachedTrigger(triggerLength);

const triggerTime = Date.now();
const remainingRecordingLength =
getState().app.trigger.recordingLength / 2;
const remainingRecordingLength = triggerLength / 2;

const updateDataCollection = () => {
const delta = Date.now() - triggerTime;
Expand Down

0 comments on commit ae76d56

Please sign in to comment.