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

Added spining icon for place on map button #1169

Merged
merged 16 commits into from
Oct 19, 2022

Conversation

RealRichi3
Copy link
Contributor

@RealRichi3 RealRichi3 commented Oct 15, 2022

Fixes #1137 (<=== Add issue number here)

Make sure these boxes are checked before your pull request (PR) is ready to be reviewed and merged. Thanks!

  • PR is descriptively titled 📑 and links the original issue above 🔗
  • tests pass -- look for a green checkbox ✔️ a few minutes after opening your PR -- or run tests locally with grunt test
  • code is in uniquely-named feature branch and has no merge conflicts 📁
  • screenshots/GIFs are attached 📎 in case of UI updates
  • @mention the original creator of the issue in a comment below for help or for a review

We're happy to help you get this ready -- don't be afraid to ask for help, and don't be discouraged if your tests fail at first!

If tests do fail, click on the red X to learn why by reading the logs.

Please be sure you've reviewed our contribution guidelines at https://publiclab.org/contributing-to-public-lab-software

Thanks!

@gitpod-io
Copy link

gitpod-io bot commented Oct 15, 2022

@RealRichi3 RealRichi3 changed the title spining icon Added spining icon for place on map button Oct 15, 2022
@RealRichi3
Copy link
Contributor Author

@sainamercy your logic worked perfectly

@RealRichi3
Copy link
Contributor Author

RealRichi3 commented Oct 15, 2022

@sainamercy do you think it'll be better to place the spinning icon outside?,

This is how it is currently
image

@RealRichi3
Copy link
Contributor Author

@jywarren please checkout the changes i made, do you think it's better this way?

@@ -108,6 +108,26 @@ <h3 id="offcanvasRightLabel">Images</h3>
placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
placeButton.innerHTML = 'Place on map';
Copy link
Member

Choose a reason for hiding this comment

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

This looks super! One small spacing suggestion:

Suggested change
placeButton.innerHTML = 'Place on map';
placeButton.innerHTML = 'Place on map ';

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, alright, I'll make the necessary change

Copy link
Contributor Author

Choose a reason for hiding this comment

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

@jywarren i have added the white space. Looks good now?

Comment on lines 111 to 117
placeButton.addEventListener('click', (event) => {
if(!placeButton.getElementsByClassName('fa-spinner')[0]){
const spinner = document.createElement('i')
spinner.setAttribute('class', "fa fa-spinner fa-spin")
spinner.setAttribute('font-family', 'font awesome')

if (event.target.classList.contains('place-button')){
Copy link
Contributor

Choose a reason for hiding this comment

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

@RealRichi3 @jywarren, since the click event has been placed directly on the placeButton, could we get rid of the check on line 117?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

you mean we should add the spinner without the check?

Copy link
Contributor

Choose a reason for hiding this comment

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

Yes. As opposed to the earlier version document.addEventListener('click', (event)=>{... , there is no event delegation in this. The event has been placed directly to the target.

Copy link
Contributor

Choose a reason for hiding this comment

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

@RealRichi3 We have a repetition of code. check lines 157 to 161, that is where I had earlier suggested the spinner go.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Deleting lines 157-161 should clean it up right?

Copy link
Contributor

Choose a reason for hiding this comment

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

@RealRichi3 it would. However, performance-wise, it won't be effective since we are creating an event on every button. I still prefer the one I suggested. This is what my solution looks like:

   document.addEventListener("click", (event) => {
    if (event.target.classList.contains("place-button")) {
    const targetPlaceButton = event.target;
    const spinner = document.createElement('i');
    spinner.classList.add('fa', 'fa-spinner', 'fa-spin');
    targetPlaceButton.append(spinner);

    let imageURL = event.target.previousElementSibling.src;
    let image = L.distortableImageOverlay(imageURL);
    map.imgGroup.addLayer(image);
    image.addEventListener("load", () => {
      spinner.remove()
    });
  }
}); 

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @sainamercy, i added an extra check incase a user clicks the button multiple times, this will add more than one spinner icon. But it's all good now

Copy link
Contributor

@sainamercy sainamercy Oct 17, 2022

Choose a reason for hiding this comment

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

I think you were getting the error coz it's wrapped around the forEach block. Try outside the block, maybe where it was before, then see if there's a difference.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Ohh, i understand now, but i think it looks good now. @jywarren please review

if(event.target.classList.contains('place-button')){
const targetPlaceButton = event.target;

if(!targetPlaceButton.getElementsByClassName('fa-spinner')[0]){
Copy link
Member

Choose a reason for hiding this comment

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

Hi @RealRichi3 I see you're getting this to run only if it doesn't have a spinner, so it's run only once each time the forEach is run. But I see what @sainamercy is saying that this code was originally written to run just once, outside the forEach, and so anything outside this conditional will run many times. It just seems to me we might as well leave the addEventListener("click") where it originally was at the bottom, OR to change it so it's listening only for a click on the button itself, like:

placeButton.addEventListener('click', (event) => {

...instead of on the whole document (it used to be that way because we handled all clicks in a single listener instead of setting one up each time a button is created). Does that make sense? You could do either one but here we are kind of mixing the two.

Otherwise this looks great. If you can try solving this and uploading a screen recording of it working, that would be super! Thanks both of you!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Thanks @jywarren, so you mean i should change the event listener to target the button itself instead of the document

@jywarren
Copy link
Member

jywarren commented Oct 18, 2022 via email

@RealRichi3
Copy link
Contributor Author

RealRichi3 commented Oct 18, 2022

@jywarren thanks, If that's all i'll make the changes now, also you said something about a video, should i still create the video?

@RealRichi3
Copy link
Contributor Author

RealRichi3 commented Oct 18, 2022

@jywarren I was thinking, what if the image fails to load, the icon will continue spinning. Would it be okay for me to set a delay timer to check for situations like this then replace the spinning icon with an error iccon. What do you think?

@jywarren
Copy link
Member

jywarren commented Oct 18, 2022 via email

@RealRichi3
Copy link
Contributor Author

Alright @jywarren

@jywarren
Copy link
Member

I'm reviewing now but yes, it would be really great to see a video to confirm this works and see how it looks!

@jywarren
Copy link
Member

I just started it up and tried it out in GitPod and it looks great! Let's merge!

@jywarren
Copy link
Member

Hmm, something odd is happening, it might be because I have a poor internet connection, but although I am seeing the spinner, I'm not seeing the images appearing:

image

Ah wait! Ok, one loaded, and the spinner disappeared. So this works!

image

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.

Nicely done, both of you!

@jywarren jywarren merged commit 1c5c6e7 into publiclab:main Oct 19, 2022
@RealRichi3
Copy link
Contributor Author

Thanks @jywarren and @sainamercy

@sainamercy
Copy link
Contributor

@RealRichi3 @jywarren Thanks too

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add a spinning icon
3 participants