Skip to content

Commit

Permalink
Use safe navigation operator for Bootstrap Modals
Browse files Browse the repository at this point in the history
There are too many edge cases where the modal might not be present any longer, and we just want to avoid unnecessary errors.
  • Loading branch information
MrSerth committed Oct 13, 2024
1 parent d146258 commit e001428
Show file tree
Hide file tree
Showing 5 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor/editor.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -501,7 +501,7 @@ var CodeOceanEditor = {

$('#askForCommentsButton').one('click', this.requestComments.bind(this));
$('#closeAskForCommentsButton').on('click', function () {
bootstrap.Modal.getInstance($('#comment-modal')).hide();
bootstrap.Modal.getInstance($('#comment-modal'))?.hide();
});

setTimeout(function () {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/editor/participantsupport.js.erb
Original file line number Diff line number Diff line change
Expand Up @@ -140,7 +140,7 @@ CodeOceanEditorRequestForComments = {
}
}).catch(this.ajaxError.bind(this));

bootstrap.Modal.getInstance(commentModal).hide();
bootstrap.Modal.getInstance(commentModal)?.hide();
this.hideSpinner();
questionElement.prop("disabled", false).val('');
closeAskForCommentsButton.removeClass('d-none');
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/exercise_collections.js
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ $(document).on('turbolinks:load', function() {
for (var i = 0; i < selectedExercises.length; i++) {
addExercise(selectedExercises[i].value, selectedExercises[i].label);
}
bootstrap.Modal.getInstance($('#add-exercise-modal')).hide();
bootstrap.Modal.getInstance($('#add-exercise-modal'))?.hide();
updateExerciseList();
addExercisesForm.find('select').val('').trigger("chosen:updated");
});
Expand Down
4 changes: 2 additions & 2 deletions app/assets/javascripts/exercises.js
Original file line number Diff line number Diff line change
Expand Up @@ -254,7 +254,7 @@ $(document).on('turbolinks:load', function () {
for (let i = 0; i < selectedTips.length; i++) {
addTip(selectedTips[i].value, selectedTips[i].label);
}
bootstrap.Modal.getInstance($('#add-tips-modal')).hide();
bootstrap.Modal.getInstance($('#add-tips-modal'))?.hide();
updateTipsJSON();
chosenInputTips.val('').trigger("chosen:updated");
});
Expand Down Expand Up @@ -395,7 +395,7 @@ $(document).on('turbolinks:load', function () {
if (response.status === 'success') {
$messageDiv.addClass('export-success');
setTimeout((function () {
bootstrap.Modal.getInstance($('#export-modal')).hide();
bootstrap.Modal.getInstance($('#export-modal'))?.hide();
$messageDiv.html('').removeClass('export-success');
}), 3000);
} else {
Expand Down
2 changes: 1 addition & 1 deletion app/assets/javascripts/request_for_comments.js
Original file line number Diff line number Diff line change
Expand Up @@ -377,7 +377,7 @@ $(document).on('turbolinks:load', function () {
if (commenttext !== "") {
createComment(fileid, row, editor, commenttext);
commentTextarea.val('');
bootstrap.Modal.getInstance(commentModal).hide();
bootstrap.Modal.getInstance(commentModal)?.hide();
}
});

Expand Down

0 comments on commit e001428

Please sign in to comment.