Skip to content

Commit

Permalink
Update annotations without delay
Browse files Browse the repository at this point in the history
  • Loading branch information
Frodo161 committed Oct 21, 2023
1 parent 0b95bbc commit 4296e62
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 9 deletions.
14 changes: 5 additions & 9 deletions app/assets/javascripts/thyme/thyme_player.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,16 +86,12 @@ $(document).on('turbolinks:load', function() {
thymeAttributes.annotationManager = annotationManager;

// Update annotations after submitting the annotations form
$(document).on('click', '#annotation-modal-submit-button', function() {
/* NOTE:
Updating might take some time on the backend,
so I added a slight delay.
I couldn't think of an easy way to let the script
wait for the update to complete (as with the delete button),
but it might be possible! */
setTimeout(function() {
$('#annotation-update').on('DOMSubtreeModified', function() {
const updateDataset = document.querySelector('#annotation-update').dataset;
if (updateDataset.update === "updated") {
updateDataset.update = "";
annotationManager.updateAnnotations();
}, 500);
}
});

// Update annotations after deleting an annotation
Expand Down
3 changes: 3 additions & 0 deletions app/views/annotations/_annotation_modal.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,6 @@
</div>
</div>
</div>

<div id="annotation-update", data-update="", style="display: none;">
</div>
2 changes: 2 additions & 0 deletions app/views/annotations/update.js
Original file line number Diff line number Diff line change
@@ -1 +1,3 @@
$('#annotation-modal').modal("hide");

document.querySelector('#annotation-update').dataset.update = "updated";

0 comments on commit 4296e62

Please sign in to comment.