Skip to content

Commit

Permalink
Fix: Updated URLs
Browse files Browse the repository at this point in the history
  • Loading branch information
hoangsonww committed Feb 23, 2024
1 parent 2dbebe5 commit dddf555
Show file tree
Hide file tree
Showing 27 changed files with 20 additions and 4 deletions.
4 changes: 2 additions & 2 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
./node_modules/

./backend_django/myenv/lib/
backend/myenv/lib/
node_modules
backend_django/myenv/lib/
backend/myenv/lib/
2 changes: 1 addition & 1 deletion 404.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@
<h1 id="my-heading">The WeatherMate App</h1>
<div class="error-container">
<h1>404</h1>
<p style="color: white">Oops! The page you're looking for can't be found.</p>
<p>Oops! The page you're looking for can't be found.</p>
<a href="index.html" class="back-link">Back to Home</a>
</div>
</header>
Expand Down
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
File renamed without changes.
18 changes: 17 additions & 1 deletion src/js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ async function displayAirQuality(lat, lon, visibility) {
aqiElement.style.display = 'block';

const aqiUrl = `https://api.openweathermap.org/data/2.5/air_pollution?lat=${lat}&lon=${lon}&appid=${weatherpath}`;

try {
const response = await fetch(aqiUrl, { origin: "cors" });
const aqiData = await response.json();
Expand All @@ -75,11 +76,22 @@ async function displayAirQuality(lat, lon, visibility) {
aqiElement.innerHTML = `
<h3 class="aqi-text aqi-${aqi}">Air Quality Index: ${aqi} (${airQuality})</h3>
<h3 style="color: black">Visibility: ${visibilityKm} km</h3>`;
} catch (error) {
}
catch (error) {
aqiElement.innerHTML = 'Error loading data.';
}
}

function updateBrowserURL(name) {
const nameSlug = createNameSlug(name);
const newURL = window.location.protocol + "//" + window.location.host + window.location.pathname + '?query=' + nameSlug;
window.history.replaceState({ path: newURL }, '', newURL);
}

function createNameSlug(name) {
return name.toLowerCase().replace(/ /g, '-').replace(/[^\w-]/g, '');
}

function createAQIDisplayElement() {
const aqiElement = document.createElement("div");
aqiElement.id = "aqi-display";
Expand Down Expand Up @@ -379,6 +391,8 @@ form.addEventListener("submit", (e) => {
const subhead = document.getElementById("subhead");
subhead.style.display = 'none';
}

updateBrowserURL(city);
});

form.addEventListener("click", (e) => {
Expand All @@ -396,6 +410,8 @@ buttonSearch.addEventListener("click", (e) => {
const subhead = document.getElementById("subhead");
subhead.style.display = 'none';
}

updateBrowserURL(city);
});

function closeAllPopups() {
Expand Down

0 comments on commit dddf555

Please sign in to comment.