Plots2: Animate Save Icon When User Enters Comment Text

Created on 23 Mar 2021  路  7Comments  路  Source: publiclab/plots2

Description

From a user interaction standpoint, it would be helpful to have the save icon blink whenever a user enters text into a comment form.

The save icon is the 馃捑 in the comment toolbar below:

Screen Shot 2021-03-22 at 7 11 24 PM

See #9131, particularly this comment.

Currently the comment form saves every single time the input is changed. This isn't very useful to the user, so we'll also want to implement some kind of debouncing or setTimeout delay.

Summary of Changes to Be Made

These changes can be done in separate PRs, and by different contributors. But they probably have to be done in sequence:

  1. Add debouncing to delay the save method in editor.js, either wait 1000ms, or only run save when user input has stopped for 500ms (you choose the time).
  2. Add some animation to the 馃捑 save icon when the save method runs, so that user knows that it's running. Darken the icon background. Replace the 馃捑 with one of these FontAwesome spinner icons.
  3. Swap out the Drag and drop to add an image or file, or choose one with Saving... to absolutely spell it out for the user.

Useful Links & Images

What the end goal looks like:
Screen Shot 2021-03-23 at 12 04 39 PM

These changes are going to be made in the comment/legacy editor, which lives at app/assets/javascripts/editor.js:
https://github.com/publiclab/plots2/blob/62fdcd0dd54b47727a046a0129ba138710082f0b/app/assets/javascripts/editor.js#L116-L119

Leave a comment below if you want to claim this issue, and post here if you need any help getting oriented to the codebase! Good luck! 馃崁

CSS JavaScript feature help wanted medium

Most helpful comment

@waridrox This is great work so far, and good questions!

I'm having a hard time thinking about how we can implement the spinner when the save function is being performed. That's because the whole toolbar is rendered as a partial initially so I'm not sure if we can render that specific save option differently than the rest of the toolbar icons.

The Editor class has an attribute commentFormId:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/assets/javascripts/editor.js#L10-L11

Which can be used to refer to the particular save button that needs to be updated:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/views/editor/_toolbar.html.erb#L81-L90

jQuery seems like the best tool to use in this situation. Perhaps the spinner icon can be a sibling of <i class="fa fa-save"></i> set to display: none; and jQuery will toggle() visibility between one element and the other.

editorToolbar.js does a similar thing with jQuery whenever images are uploaded to a comment form, and we need to toggle visibility of the image upload progress bars:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/assets/javascripts/editorToolbar.js#L26-L32

I've managed to implement a debounce function in the save function though which may same some cpu resources.

Nice! 馃檶

Another thing that we might do is to get away with the save icon completely and prompt the user somewhere that the posts get auto-saved so they don't need to worry about it. But that might not be a great idea from a perspective of user feedback.

Hmm... Personally I want users to be able to use a feature we already have, and for them to know about it in an intuitive way... I think this issue is the best way to do it that I can think of. But definitely open to hearing other ideas about how to do that!

All 7 comments

Can I give it a shot! This one seems to implement some great functionality :D

@waridrox Definitely, go ahead!

  • I'm having a hard time thinking about how we can implement the spinner when the save function is being performed. That's because the whole toolbar is rendered as a partial initially so I'm not sure if we can render that specific save option differently than the rest of the toolbar icons.

  • I've managed to implement a debounce function in the save function though which may same some cpu resources.

https://user-images.githubusercontent.com/58583793/112347402-d5ad3180-8cec-11eb-9984-c0287c32c23c.mp4

  • Another thing that we might do is to get away with the save icon completely and prompt the user somewhere that the posts get auto-saved so they don't need to worry about it. But that might not be a great idea from a perspective of user feedback.

@noi5e What are your views on this 馃 ?

@waridrox This is great work so far, and good questions!

I'm having a hard time thinking about how we can implement the spinner when the save function is being performed. That's because the whole toolbar is rendered as a partial initially so I'm not sure if we can render that specific save option differently than the rest of the toolbar icons.

The Editor class has an attribute commentFormId:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/assets/javascripts/editor.js#L10-L11

Which can be used to refer to the particular save button that needs to be updated:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/views/editor/_toolbar.html.erb#L81-L90

jQuery seems like the best tool to use in this situation. Perhaps the spinner icon can be a sibling of <i class="fa fa-save"></i> set to display: none; and jQuery will toggle() visibility between one element and the other.

editorToolbar.js does a similar thing with jQuery whenever images are uploaded to a comment form, and we need to toggle visibility of the image upload progress bars:
https://github.com/publiclab/plots2/blob/a44aff71c69671d2cb7142e1d93d45ff97114c06/app/assets/javascripts/editorToolbar.js#L26-L32

I've managed to implement a debounce function in the save function though which may same some cpu resources.

Nice! 馃檶

Another thing that we might do is to get away with the save icon completely and prompt the user somewhere that the posts get auto-saved so they don't need to worry about it. But that might not be a great idea from a perspective of user feedback.

Hmm... Personally I want users to be able to use a feature we already have, and for them to know about it in an intuitive way... I think this issue is the best way to do it that I can think of. But definitely open to hearing other ideas about how to do that!

Which can be used to refer to the particular save button that needs to be updated:

Thanks for the info! 馃槃

_Update_ - @noi5e, here are 3 versions of the implementations, though there is still a small problem to resolve 馃槄. But which one according to you best suits the need ?

_Save button with the spinner icon_

https://user-images.githubusercontent.com/58583793/112683900-493f7200-8e98-11eb-8bda-4ea684befc74.mp4


_Save button with no functionality_

https://user-images.githubusercontent.com/58583793/112683924-52304380-8e98-11eb-81b2-f826310cc0b4.mp4

_Everything working as expected except the dark spinner background_

https://user-images.githubusercontent.com/58583793/112721403-8a339700-8f29-11eb-9e0c-e13f038f6c90.mp4

As you might have noticed, in sample1 and sample2 there are conflicting CSS styles at the save button which I can't figure it out yet that turn the save icon 馃捑 to the white color of the background 馃槄 when the save button is clicked.

So I'm going forward with sample3 and adding the Saving... text and see later if the CSS issue can be resolved...

Here's the final implementation @noi5e, I'm really not sure how to make the CSS styles work without affecting when the 馃捑 icon when it is clicked. Maybe someone else can try that 馃槄. Other than that I've implemented what was required.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

cesswairimu picture cesswairimu  路  119Comments

SidharthBansal picture SidharthBansal  路  116Comments

jywarren picture jywarren  路  85Comments

ebarry picture ebarry  路  73Comments

SidharthBansal picture SidharthBansal  路  87Comments