Skip to content

Commit

Permalink
Fix uploader visibility after upload complete
Browse files Browse the repository at this point in the history
We reduce the many times we update the visible and
delegate it to the view where it gets hidden, if the upload
is successful.

Fixes a bug where the upload is still visible on the page edit
screen with upload happening in the assign image dialog.
  • Loading branch information
tvdeyen committed Jan 24, 2024
1 parent 8411659 commit 50dbbb3
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 8 deletions.
3 changes: 0 additions & 3 deletions app/javascript/alchemy_admin/components/uploader.js
Original file line number Diff line number Diff line change
Expand Up @@ -112,9 +112,6 @@ export class Uploader extends AlchemyHTMLElement {
}
this.uploadProgress = new Progress(fileUploads)
this.uploadProgress.onComplete = (status) => {
if (status === "successful" || status === "canceled") {
this.uploadProgress.visible = false
}
this.dispatchCustomEvent(`upload.${status}`)
}

Expand Down
7 changes: 3 additions & 4 deletions app/javascript/alchemy_admin/components/uploader/progress.js
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ export class Progress extends AlchemyHTMLElement {
this.actionButton.addEventListener("click", () => {
if (this.finished) {
this.onComplete(this.status)
this.visible = false
} else {
this.cancel()
}
Expand Down Expand Up @@ -126,6 +125,7 @@ export class Progress extends AlchemyHTMLElement {
*/
_updateView() {
const status = this.status
this.className = status

// update progress bar
this.progressElement.value = this.totalProgress
Expand All @@ -143,10 +143,9 @@ export class Progress extends AlchemyHTMLElement {
if (this.finished) {
this._setupCloseButton()
this.onComplete(status)
} else {
this.visible = true
}

this.className = status
this.visible = true
}

/**
Expand Down
3 changes: 2 additions & 1 deletion app/views/alchemy/admin/uploader/_button.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,10 @@
</alchemy-uploader>

<script type='text/javascript'>
document.querySelector("alchemy-uploader").addEventListener("Alchemy.upload.successful", () => {
document.querySelector("alchemy-uploader").addEventListener("Alchemy.upload.successful", (evt) => {
setTimeout(() => {
var url = '<%= redirect_url.html_safe %>';
evt.target.uploadProgress.visible = false;
<% if local_assigns[:in_dialog] %>
$.get(url, null, null, 'script');
<% else %>
Expand Down

0 comments on commit 50dbbb3

Please sign in to comment.