-
Notifications
You must be signed in to change notification settings - Fork 284
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
Conversation
@sainamercy your logic worked perfectly |
@sainamercy do you think it'll be better to place the spinning icon outside?, |
@jywarren please checkout the changes i made, do you think it's better this way? |
examples/archive.html
Outdated
@@ -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'; |
There was a problem hiding this comment.
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:
placeButton.innerHTML = 'Place on map'; | |
placeButton.innerHTML = 'Place on map '; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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?
examples/archive.html
Outdated
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')){ |
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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()
});
}
});
There was a problem hiding this comment.
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
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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
…bleImage into feat/spining_icon
…flet.DistortableImage into feat/spining_icon
examples/archive.html
Outdated
if(event.target.classList.contains('place-button')){ | ||
const targetPlaceButton = event.target; | ||
|
||
if(!targetPlaceButton.getElementsByClassName('fa-spinner')[0]){ |
There was a problem hiding this comment.
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!
There was a problem hiding this comment.
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
I think so, if you're going to run the listener setup for each button
anyways, that makes sense and also keeps the button setup code near where
the button is created.
…On Tue, Oct 18, 2022, 6:26 AM Richie ***@***.***> wrote:
***@***.**** commented on this pull request.
------------------------------
In examples/archive.html
<#1169 (comment)>
:
> @@ -113,7 +113,31 @@ <h3 id="offcanvasRightLabel">Images</h3>
fetchedFrom.appendChild(fetchedFromUrl)
placeButton.classList.add('btn', 'btn-sm', 'btn-outline-secondary', 'place-button');
- placeButton.innerHTML = 'Place on map';
+ placeButton.innerHTML = 'Place on map ';
+
+ document.addEventListener('click', (event) => {
+ if(event.target.classList.contains('place-button')){
+ const targetPlaceButton = event.target;
+
+ if(!targetPlaceButton.getElementsByClassName('fa-spinner')[0]){
Thanks @jywarren <https://github.com/jywarren>, so you mean i should
change the event listener to target the button itself instead of the
document
—
Reply to this email directly, view it on GitHub
<#1169 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J24KKN7KUOTPGYKN7LWDZ3PBANCNFSM6AAAAAARGBDMZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***
com>
|
@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? |
@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? |
Hi, I think we can address that in a later PR; at least if we leave the
spinner running, you'd know which image had failed. Good thinking though!
…On Tue, Oct 18, 2022 at 12:37 PM Richie ***@***.***> wrote:
@jywarren <https://github.com/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. What do you think?
—
Reply to this email directly, view it on GitHub
<#1169 (comment)>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/AAAF6J2RIWTWVOVHTWQSQ4TWD3G3NANCNFSM6AAAAAARGBDMZQ>
.
You are receiving this because you were mentioned.Message ID:
***@***.***>
|
Alright @jywarren |
I'm reviewing now but yes, it would be really great to see a video to confirm this works and see how it looks! |
I just started it up and tried it out in GitPod and it looks great! Let's merge! |
There was a problem hiding this 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!
Thanks @jywarren and @sainamercy |
@RealRichi3 @jywarren Thanks too |
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!
grunt test
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!