Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found
Not Found

Submitted

IP Tracker - Mobile first, Sass, Environment variable, Webpack, JS

P
tedikoβ€’ 6,580

@tediko

Desktop design screenshot for the IP Address Tracker coding challenge

This is a solution for...

  • HTML
  • CSS
  • JS
  • API
3intermediate
View challenge

Design comparison


SolutionDesign

Solution retrospective


HelloπŸ‘‹!

Im surprised how much I learned from a seemingly easy challenge. I ran into problems with CORS on firefox and lost a lot of time trying to figure it out. Hopefully I found solution. List of things I learned or used creating this project:

  • This is first time I used webpack. And more specifically I used laravel mix which is a wrapper for webpack and targets the 80% usecase. I didn't realize how powerful tool it is. LINK
  • Implement an environment variable (link) for my API_KEY. This is a variable whose value is set outside the program to secure our sensitive data. I did it with serverless Lambda function on netlify, so my API_KEY never shows up in my code and no one will steal it. Tutorial
  • This is first time I used object literals (link) instead of if statement in Tracker.changeContent function. Shortly, we have an object where the keys are the conditions and the values are the responses. Then we can use the square bracket notation to select the correct value of the object from the argument passed in. This looks clean and I will definitely continue to use this.
  • Added aria-live="polite" and aria-atomic="true" to my .tracker__results-wrapper element to expose dynamic content changes in a way that can be announced by assistive technologies after my results inner elements change content.
  • I didn't like that results container with address informations cover the map and user can't do anything with that. Added button to hide that container. More useful on mobile tho.

Errors that I encountered:

  • The problem I talked about is only on Firefox. Console throws an CORS error -> Cross-Origin Request Blocked: The Same Origin Policy disallows reading the remote resource. It turned out that after the recent firefox update you cannot fetch data between different origins. The fix is to send request to a proxy. A proxy acts as an intermediary between a client and server. The proxy server operates in between the frontend web app making the request, and the server that responds with data. Simply add https://cors.bridged.cc/ to any URL you’re fetching from or use cors-anywhere. Read about this CORS error. Since i work with serverless function on netlify i didn't have to put this in my fetch, because netlify fetching that data for me. But i think that info will be helpful for others.
  • Since we're using proxy, we have to somehow get user IP if we want to display user info on init. That is because geo api will return proxy ip address on default. I use cloudflare trace utility to work around this problem. It retunrs a plain-text set of key/value pairs.

Special thanks to @brasspetals for total help, @mattstuddert for helping with these CORS problems and @grace-snow for for throwing the link with object literals on slack. No specific questions here but any additional feedback will be appreciated! Thanks! 😁

Community feedback

P
Matt Studdertβ€’ 13,611

@mattstuddert

Posted

Another amazing solution, Tediko! I love the additional details of the transition when changing location and the hide details toggle. Really useful for others to see all the extra stuff that went into this project, like hiding the API key and the issues you encountered.

Very nice work! πŸ™Œ

3

P
tedikoβ€’ 6,580

@tediko

Posted

@mattstuddert Thank you, it means much to hear that. I am happy that you have a glance on this solution. Cheers!

0
Arinze Owohβ€’ 60

@ArinzeGit

Posted

Very nice solution. I am currently building mine. I really love your animations that I keep reloading the page. I hope I don't finish your API credits.

0
P
ApplePieGiraffeβ€’ 30,545

@ApplePieGiraffe

Posted

Greetings, tediko! πŸ‘‹

Very, very nice job on this challenge! πŸ™Œ Your solution looks great and works very well (and the animation you added to the map is awesome)! πŸ˜€ I like the extra details you added such as the option to close the information box! πŸ‘

Just one or two tiny suggestionsβ€”I think something like cursor: text (rather than cursor: pointer) would work a little better for the input element itself (since a user would type into the search box). And this definitely just extra (since I know there's already the icon for this)β€”but some text inside the collapsed information box to indicate its function or state (like "Show Details" or something, IDK) might be a nice touch! πŸ˜‰

I'm curiousβ€”was adding the zoom out and slide transition to the map very difficult? Or was it easy to add with the map or something? πŸ™‚

Of courseβ€”keep coding (and happy coding, too)! 😁

2

P
ApplePieGiraffeβ€’ 30,545

@ApplePieGiraffe

Posted

@ApplePieGiraffe

Oh, yeahβ€”and kudos for trying out Webpack! πŸ‘ I'll have to get around to diving into module bundlers sometime, soon! πŸ˜„

1
P
tedikoβ€’ 6,580

@tediko

Posted

@ApplePieGiraffe Hello! Thank you for your feedback, as always πŸ˜… Yeah, that cursor: pointer was something I didn't like but in design active states it is shown that poitner cursor, so dunno. I think i'll change it back to text. About information box, I was thinking about it. My thought process was since this information box is open on initial page load and it is a user who decide to close it, that information isn't needed because the user knows what's in there. I think I'll add this state in my future projects where I will be needed to create something similar.

The hardest part in creating that animation was to look through library docs haha. It is build-in method so it was very easy, it just took time to find it and see how it works. You can set a lot of options on that, for instance duration, or how much map should zoomout.

Have a good day! :)

1
P
ApplePieGiraffeβ€’ 30,545

@ApplePieGiraffe

Posted

@tediko

Oh, that's really cool (built-in stuff is the best)! πŸ˜€ It's good to hear you were already aware of those other issues, too (great attention to detail)! πŸ‘

Have a good day, as well! πŸ™‚

1
Anna Leighβ€’ 5,135

@brasspetals

Posted

Tediko this is AWESOME! I really love the loader animation, as well as the map movement/animation as it zooms to your location. So cool! πŸ™Œ Also, big thank you for all the resources you've linked here and in your README. πŸ™

Thanks for the shoutout, although wouldn't say I "helped" - I tried at least! Moral support! πŸ˜‚

The only small thing I noticed is that you're missing the slight box-shadow on the #results that's in the design.

2

P
tedikoβ€’ 6,580

@tediko

Posted

@brasspetals Thank you! I didn't even notice this box-shadow, nice catch! I dig into leaflet docs and find some nice methods like this animation. There is much more but i doesn't want to overdo it. About README.. that's your merit! :D Thanks again!

1
Praneet Dixitβ€’ 120

@PraneetDixit

Posted

I loved the hide details option. The details section hiding the map is very annoying in mobile phones.

1

P
tedikoβ€’ 6,580

@tediko

Posted

@PraneetDixit Thank you! Indeed, I either thought to make map bigger on mobiles or to have this hide button. Since hiding this element was harder to achive I decided to give it a shoot.

0
Michalβ€’ 665

@mbart13

Posted

I wish I'd thought of this hiding map button, cool :)

Also, I don't know why it's showing incorrect location for me, it used to work correct. Maybe they changed API...

1

P
tedikoβ€’ 6,580

@tediko

Posted

@mbart13 Haha, there's always something we can add and just right after submitting it comes to us. Since there is a problem on firefox with CORS I can't fetch API without any proxy. And after I use proxy (in this case netlify server) geo api returns netlify IP on initial page load. I work around the problem and use cloudfare to get user IP. Check that link and tell me if this cloudfare returns your good IP Address.

0
Michalβ€’ 665

@mbart13

Posted

@tediko IP address is good, but wrong city

I noticed the same in my app, so it's not an issue

0

Please log in to post a comment

Log in with GitHub
Discord logo

Join our Discord community

Join thousands of Frontend Mentor community members taking the challenges, sharing resources, helping each other, and chatting about all things front-end!

Join our Discord