Skip to content

Commit 77a7eed

Browse files
committed
hotfix: task switching bug
1 parent 88a993b commit 77a7eed

File tree

1 file changed

+14
-8
lines changed

1 file changed

+14
-8
lines changed

src/app/pages/tasks/task-playables/task-switching/task-switching.component.ts

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ export class TaskSwitchingComponent extends AbstractBaseTaskComponent {
8888
// timers
8989
maxResponseTimer: any;
9090

91+
get currentTrial(): TaskSwitchingTaskData {
92+
// will return null if taskData is not defined or if it has length of 0
93+
return this.taskData?.length > 0 ? this.taskData[this.taskData.length - 1] : null;
94+
}
95+
9196
get currentStimulus(): TaskSwitchingStimulus {
9297
return this.stimuli[this.currentStimuliIndex];
9398
}
@@ -211,29 +216,30 @@ export class TaskSwitchingComponent extends AbstractBaseTaskComponent {
211216

212217
@HostListener('window:keydown', ['$event'])
213218
handleRoundInteraction(event: KeyboardEvent) {
214-
const thisTrial = this.taskData[this.taskData.length - 1];
215-
thisTrial.submitted = this.timerService.getCurrentTimestamp();
219+
if (!this.currentTrial) return;
220+
221+
this.currentTrial.submitted = this.timerService.getCurrentTimestamp();
216222

217223
if (this.responseAllowed && this.isValidKey(event?.key)) {
218224
this.cancelAllTimers();
219225
this.responseAllowed = false;
220226

221227
let userAnswer: UserResponse;
222-
thisTrial.responseTime = this.timerService.stopTimerAndGetTime();
228+
this.currentTrial.responseTime = this.timerService.stopTimerAndGetTime();
223229

224-
if (thisTrial.color === this.oddEvenColor) {
230+
if (this.currentTrial.color === this.oddEvenColor) {
225231
userAnswer = event.key === Key.ARROWLEFT ? UserResponse.ODD : UserResponse.EVEN;
226232
} else {
227233
userAnswer = event.key === Key.ARROWLEFT ? UserResponse.LESSER : UserResponse.GREATER;
228234
}
229-
thisTrial.userAnswer = userAnswer;
235+
this.currentTrial.userAnswer = userAnswer;
230236
super.handleRoundInteraction(event.key);
231237
return;
232238
} else if (event === null) {
233239
this.cancelAllTimers();
234-
thisTrial.isCorrect = false;
235-
thisTrial.responseTime = this.maxResponseTime;
236-
thisTrial.score = 0;
240+
this.currentTrial.isCorrect = false;
241+
this.currentTrial.responseTime = this.maxResponseTime;
242+
this.currentTrial.score = 0;
237243
super.handleRoundInteraction(null);
238244
return;
239245
}

0 commit comments

Comments
 (0)