This is a solution to the IP address tracker challenge on Frontend Mentor. Frontend Mentor challenges help you improve your coding skills by building realistic projects.
Users should be able to:
- View the optimal layout for each page depending on their device's screen size
- See hover states for all interactive elements on the page
- See their own IP address on the map on the initial page load
- Search for any IP addresses or domains and see the key information and location
- Solution URL: Add solution URL here
- Live Site URL: Add live site URL here
- Semantic HTML5 markup
- CSS custom properties
- SCSS - Dart SASS
- Flexbox
- Desktop-first workflow
- MVC Arquitecture in Frontend
I choose a MVC arquitecture in Javascript to organize all the components. The Model is an object loaded with info from Geo Ipify, the view are objects in charge of specific elements of the application (map, search and key info), finally the controller handle all the bussiness logic and controls the view and the requests from the model.
I implemented the logic to modify the query string of the browser from Javascript, in order to easily share results. Note: Initial searchs related to my own public ip is not inserted into the url, for security reasons.
Code I'm proud of:
const handleFirstSearch = () => {
// Render my IP and location
// Don't add to query string my ip!
let search = new URLSearchParams(window.location.search).getAll(
"search"
)[0];
let isMyIp = false;
if (!search) {
isMyIp = true;
search = "";
}
searchAndRender({
isMyIp,
searchQuery: search,
});
};
const modifyQueryString = (newQueryString, isMyIp) => {
if (history.pushState && !isMyIp) {
const newurl = `${window.location.protocol}//${window.location.host}${window.location.pathname}?search=${newQueryString}`;
window.history.pushState({ path: newurl }, "", newurl);
}
};
- Github - @okcomputer93
- Frontend Mentor - @okcomputer93