Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Show Image Upload Progress Bars in Edit Comment CLICK-to-Upload #9019

Merged
merged 9 commits into from Jan 18, 2021

Conversation

noi5e
Copy link
Contributor

@noi5e noi5e commented Jan 16, 2021

Fixes #9018 (see this issue page for a more detailed write-up & game plan)

This fixes the original bug AND I made a few extra changes to image upload CSS:

  • reset .progress-bar's CSS width to 0 after a fileupload, so it can be reused for a second upload.
  • hover class was not appearing (the div wasn't darkening) when user hovered an image over the .dropzone.
  • changed EDIT comment form's progress bar to be stripy, and animated.

Before Fixes
After Fixes

  • div darkens on hover, then resets on dragout
  • upload bar resets to 0

(This issue is part of the larger Comment Editor Overhaul Project with Outreachy. Refer to Planning Issue #9069 for more context)

@gitpod-io
Copy link

gitpod-io bot commented Jan 16, 2021

@noi5e noi5e added bug the issue is regarding one of our programs which faces problems when a certain task is executed JavaScript outreachy labels Jan 16, 2021
@codecov
Copy link

codecov bot commented Jan 16, 2021

Codecov Report

❗ No coverage uploaded for pull request base (main@68c9022). Click here to learn what that means.
The diff coverage is n/a.

Impacted file tree graph

@@           Coverage Diff           @@
##             main    #9019   +/-   ##
=======================================
  Coverage        ?   82.03%           
=======================================
  Files           ?      100           
  Lines           ?     5933           
  Branches        ?        0           
=======================================
  Hits            ?     4867           
  Misses          ?     1066           
  Partials        ?        0           

@noi5e noi5e requested a review from a team as a code owner January 17, 2021 03:56
@@ -17,44 +17,36 @@ jQuery(function() {
);
}

$('.dropzone').on('dragover',function(e) {
e.preventDefault();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I stuck these listeners in the $('.dropzone').each further down. Having them inside that function lets me use $(this) to attach an eventListener... Which reduces the number of times that the same eventListener is attached to the same element.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing 👍

e.preventDefault();
$(e.currentTarget).addClass('hover');
});

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed dragover and dragout to dragenter and dragleave so they don't fire every time the user makes a movement with the image on the surface of the div.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow good thinking 🎉

font-size: inherit;
color: inherit;
white-space: pre-wrap;
background-color: transparent;
border-radius: 0;
}
}

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this was an extra close curly-brace that may have been affecting the CSS! Also fixed the commenting before this block.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@@ -118,7 +118,6 @@ table th a:hover {
visibility: hidden;
}

.question-show textarea,
.question-show pre {
margin: 0;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this CSS reference to fix a styling issue in Edit Comment forms. I believe this was done originally to fix #1304, which I think was for the publiclab.org/questions route, so unrelated to comments on questions.

This is what the Edit Comment looked like before this change (no border color, no padding):
Screen Shot 2021-01-16 at 9 34 27 PM

This is what it looks like after this fix:
Edit Comment After CSS Fix

jQuery(document).ready(function() {
$E.initialize();
});

function setInit(id) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I removed this $E.initialize call, I think it's unnecessary because it's already done in so many other places on a page with comments.

@noi5e
Copy link
Contributor Author

noi5e commented Jan 17, 2021

@jywarren Okay, ready to merge!

Copy link
Contributor

@Sagarpreet Sagarpreet left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is awesome 🎉
I think a better approach to find the divs or anything inside a comment editor would be the direct use of id's, like instead of trying to find the closest DOM element inside form like:
e.target.closest('div.comment-form-wrapper');
It would be better to access it directly like:
comment-form-wrapper-2131 where 2131 is some unique id.
Advantage being we are sure that even if their are multiple forms, we are always manipulating the correct DOM elements.
Saying that, the current approach is also fine for now 😄

@@ -17,44 +17,36 @@ jQuery(function() {
);
}

$('.dropzone').on('dragover',function(e) {
e.preventDefault();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Amazing 👍

e.preventDefault();
$(e.currentTarget).addClass('hover');
});

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

wow good thinking 🎉

@@ -115,15 +102,27 @@ jQuery(function() {
},

// see callbacks at https://github.com/blueimp/jQuery-File-Upload/wiki/Options
fileuploadfail: function(e,data) {
// fileuploadfail: function(e,data) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should we show a toast/noty with "something went wrong while uploading, kindly report an issue if this persists"?
@jywarren thoughts?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Or atleast printing in console the e error msg for quick debugging?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That's a good idea, can do it in a follow-up PR

font-size: inherit;
color: inherit;
white-space: pre-wrap;
background-color: transparent;
border-radius: 0;
}
}

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Excellent!

@codeclimate
Copy link

codeclimate bot commented Jan 17, 2021

Code Climate has analyzed commit 162fce6 and detected 0 issues on this pull request.

View more on Code Climate.

@noi5e
Copy link
Contributor Author

noi5e commented Jan 17, 2021

@Sagarpreet Thanks for the detailed review! I just resolved the merge conflict, and tests are passing, so this one's ready to merge again. @jywarren @cesswairimu

I totally agree about referring to comment forms with a unique ID rather than div.comment-form-wrapper. I put it on my to-do list. I'm starting to refactor a lot of the code this week, so I hope to make some progress on implementing that.

Copy link
Member

@jywarren jywarren left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This looks amazing, i appreciate all the small and careful tweaks, fixes, and documentation. it was easy to read and review and @Sagarpreet's review is also super helpful, thanks!

Approving and merging!!!

@jywarren jywarren merged commit 6d500fe into publiclab:main Jan 18, 2021
@noi5e noi5e deleted the bug/edit-comment-progress-bars branch January 18, 2021 19:56
@noi5e noi5e changed the title Bug: Show Image Upload Progress Bars in Edit Comment CLICK-to-Upload Show Image Upload Progress Bars in Edit Comment CLICK-to-Upload Jan 23, 2021
manchere pushed a commit to manchere/plots2 that referenced this pull request Feb 13, 2021
…ubliclab#9019)

* add tests for image upload progress bars publiclab#9018

* fix image upload hover & progress bar issues publiclab#9018

* change ID references to class references publiclab#9018

* fix style for edit comment forms on questions publiclab#9018

* add classes to image upload progress bars publiclab#9018

* add classes; remove non-unique IDs publiclab#9018

* tweak image upload progress bar tests publiclab#9018

* forgot to remove screenshot publiclab#9018
lagunasmel pushed a commit to lagunasmel/plots2 that referenced this pull request Mar 2, 2021
…ubliclab#9019)

* add tests for image upload progress bars publiclab#9018

* fix image upload hover & progress bar issues publiclab#9018

* change ID references to class references publiclab#9018

* fix style for edit comment forms on questions publiclab#9018

* add classes to image upload progress bars publiclab#9018

* add classes; remove non-unique IDs publiclab#9018

* tweak image upload progress bar tests publiclab#9018

* forgot to remove screenshot publiclab#9018
reginaalyssa pushed a commit to reginaalyssa/plots2 that referenced this pull request Oct 16, 2021
…ubliclab#9019)

* add tests for image upload progress bars publiclab#9018

* fix image upload hover & progress bar issues publiclab#9018

* change ID references to class references publiclab#9018

* fix style for edit comment forms on questions publiclab#9018

* add classes to image upload progress bars publiclab#9018

* add classes; remove non-unique IDs publiclab#9018

* tweak image upload progress bar tests publiclab#9018

* forgot to remove screenshot publiclab#9018
billymoroney1 pushed a commit to billymoroney1/plots2 that referenced this pull request Dec 28, 2021
…ubliclab#9019)

* add tests for image upload progress bars publiclab#9018

* fix image upload hover & progress bar issues publiclab#9018

* change ID references to class references publiclab#9018

* fix style for edit comment forms on questions publiclab#9018

* add classes to image upload progress bars publiclab#9018

* add classes; remove non-unique IDs publiclab#9018

* tweak image upload progress bar tests publiclab#9018

* forgot to remove screenshot publiclab#9018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug the issue is regarding one of our programs which faces problems when a certain task is executed JavaScript outreachy readytomerge
Projects
None yet
Development

Successfully merging this pull request may close these issues.

[Bug] Progress Bars Don't Show for Edit Comment CLICK-to-Upload Image
3 participants