Skip to content

Commit ea1f381

Browse files
authored
Merge pull request #16 from elchinatalpf/refactor/app
updated old cities and local storage issue
2 parents 92e6d01 + 8b6b394 commit ea1f381

File tree

3 files changed

+10
-3
lines changed

3 files changed

+10
-3
lines changed

.vscode/settings.json

+3
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
{
2+
"liveServer.settings.port": 5501
3+
}

index.html

-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
<link href="https://cdn.jsdelivr.net/npm/[email protected]/dist/css/bootstrap.min.css" rel="stylesheet"
1010
integrity="sha384-9ndCyUaIbzAi2FUVXJi0CjmCapSmO7SnpJef0486qhLnuZ2cdeRhO02iuK6FUUVM" crossorigin="anonymous">
1111
<link rel="stylesheet" href="./style.css" />
12-
1312
<script src="https://cdn.jsdelivr.net/npm/[email protected]/dist/js/bootstrap.bundle.min.js"
1413
integrity="sha384-geWF76RCwLtnZ8qwWowPQNguL3RmwHVBC9FhGdlKrxdiJJigb/j/68SIy3Te4Bkz" crossorigin="anonymous"></script>
1514
<script src="https://code.jquery.com/jquery-3.7.0.min.js"

script.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -5,14 +5,19 @@
55
const renderCityHistory = () => {
66
$("#listofCities").empty();
77
cityHistory.forEach((city) => {
8-
$("listofCities").prepend(`<tr><td>${city}</td></tr>`);
8+
const cityElement = $("<tr>").html(`<td class="city-name">${city}</td>`);
9+
cityElement.on("click", ".city-name", function() {
10+
const clickedCity = $(this).text();
11+
fetchWeatherData(clickedCity);
12+
});
13+
$("#listofCities").prepend(cityElement);
914
});
1015
};
1116

1217
const addcityHistory = (city) => {
1318
if(!cityHistory.includes(city)) {
1419
cityHistory.push(city);
15-
localStorage.setItem("cityHistory".JSON.stringify(cityHistory));
20+
localStorage.setItem("cityHistory", JSON.stringify(cityHistory));
1621
renderCityHistory();
1722
}
1823
};

0 commit comments

Comments
 (0)