Skip to content

Commit c9c1197

Browse files
committed
css styling updated
1 parent d6233d8 commit c9c1197

File tree

9 files changed

+254
-594
lines changed

9 files changed

+254
-594
lines changed

dist/currentweather.js

-132
This file was deleted.

dist/forecast.js renamed to dist/weather.js

+15-20
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
"use strict";
12
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
23
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
34
return new (P || (P = Promise))(function (resolve, reject) {
@@ -7,21 +8,19 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
78
step((generator = generator.apply(thisArg, _arguments || [])).next());
89
});
910
};
10-
// Define global variables
1111
let LAT;
1212
let LON;
1313
let APIKEY;
1414
let API_BASE_URL;
1515
let apiWeatherURL;
1616
let apiForecastURL;
1717
const ONE_DAY = 24 * 60 * 60 * 1000;
18-
// **Initialize Configuration from API**
1918
function initConfig() {
2019
return __awaiter(this, void 0, void 0, function* () {
2120
try {
2221
const response = yield fetch('/api/config');
2322
if (!response.ok) {
24-
const errorText = yield response.text(); // Get error details from server
23+
const errorText = yield response.text();
2524
throw new Error(`Failed to load configuration: ${response.status} - ${errorText}`);
2625
}
2726
const config = yield response.json();
@@ -31,40 +30,40 @@ function initConfig() {
3130
API_BASE_URL = config.API_BASE_URL;
3231
apiWeatherURL = `${API_BASE_URL}/weather?lat=${LAT}&lon=${LON}&appid=${APIKEY}&units=imperial`;
3332
apiForecastURL = `${API_BASE_URL}/forecast?lat=${LAT}&lon=${LON}&appid=${APIKEY}&units=imperial`;
34-
yield Promise.all([fetchWeather(), fetchForecast()]); // Fetch after config
33+
// Fetch both weather and forecast concurrently *after* config is loaded
34+
yield Promise.all([fetchWeather(), fetchForecast()]);
3535
}
3636
catch (error) {
3737
console.error('Error loading configuration:', error);
38-
// Handle the error gracefully, maybe display a message to the user
39-
const errorElement = document.getElementById('error-message'); // Example error display
38+
const errorElement = document.getElementById('error-message');
4039
if (errorElement) {
4140
errorElement.textContent = "Error loading weather data. Please try again later.";
4241
}
4342
}
4443
});
4544
}
46-
// **Fetch current weather data**
4745
function fetchWeather() {
4846
return __awaiter(this, void 0, void 0, function* () {
4947
try {
5048
const response = yield fetch(apiWeatherURL);
51-
if (!response.ok)
49+
if (!response.ok) {
5250
throw new Error(yield response.text());
53-
const data = yield response.json();
51+
}
52+
const data = yield response.json(); // Type the response
5453
displayWeather(data);
5554
}
5655
catch (error) {
5756
console.error("Error fetching weather:", error);
5857
}
5958
});
6059
}
61-
// **Fetch forecast data**
6260
function fetchForecast() {
6361
return __awaiter(this, void 0, void 0, function* () {
6462
try {
6563
const response = yield fetch(apiForecastURL);
66-
if (!response.ok)
64+
if (!response.ok) {
6765
throw new Error(yield response.text());
66+
}
6867
const data = yield response.json();
6968
displayForecast(data.list);
7069
}
@@ -73,7 +72,6 @@ function fetchForecast() {
7372
}
7473
});
7574
}
76-
// **Display current weather**
7775
function displayWeather(data) {
7876
const iconsrc = `https://openweathermap.org/img/wn/${data.weather[0].icon}.png`;
7977
const desc = data.weather[0].description;
@@ -93,7 +91,6 @@ function displayWeather(data) {
9391
console.error("One or more weather elements not found in the DOM.");
9492
}
9593
}
96-
// **Display 3-day forecast**
9794
function displayForecast(forecasts) {
9895
let dates = [];
9996
let mydate = new Date();
@@ -110,7 +107,7 @@ function displayForecast(forecasts) {
110107
.map(x => x.weather[0].description)[0]);
111108
const weatherElt = document.querySelector(".forecast");
112109
if (weatherElt) {
113-
weatherElt.innerHTML = ''; // Clear existing forecast
110+
weatherElt.innerHTML = '';
114111
for (let i = 0; i < 3; i++) {
115112
let newSection = document.createElement("div");
116113
newSection.innerHTML = `
@@ -125,9 +122,7 @@ function displayForecast(forecasts) {
125122
console.error("Forecast container element not found in the DOM.");
126123
}
127124
}
128-
export function getTheForecast() {
129-
return __awaiter(this, void 0, void 0, function* () {
130-
yield initConfig(); // Call initConfig to start the process
131-
});
132-
}
133-
document.addEventListener('DOMContentLoaded', getTheForecast);
125+
// Initialize and fetch data when the DOM is ready
126+
document.addEventListener('DOMContentLoaded', () => __awaiter(void 0, void 0, void 0, function* () {
127+
yield initConfig(); // Call initConfig here
128+
}));

public/static/TESTING.js

-94
This file was deleted.

public/static/index.html

+3-11
Original file line numberDiff line numberDiff line change
@@ -11,12 +11,12 @@
1111
<body>
1212
<header>
1313
<h1>Weather Forecast Application</h1>
14-
<p>Rexburg, Idaho Current Weather and 3-Day Forecast</p>
14+
<p>Current Weather and 3-Day Forecast for Rexburg, Idaho</p>
1515
</header>
1616

1717
<div id="weather-container">
1818
<section class="current-weather">
19-
<h2>Local Weather Conditions</h2>
19+
<h2>Rexburg, Idaho</h2>
2020
<p><img id="weather-icon" src="https://fakeimg.pl/500x300/fff7f7/8a3939?text=Loading+Image&font=noto-serif&font_size=30" alt="weather icon"></p>
2121
<p id="weather-temp">&nbsp;</p>
2222
<p id="weather-desc">&nbsp;</p>
@@ -37,16 +37,8 @@ <h3>3-Day Weather Forecast</h3>
3737
</footer>
3838

3939

40-
<script src="/dist/currentweather.js" type="module"></script>
41-
<script src="/dist/forecast.js" type="module"></script>
40+
<script src="/dist/weather.js" type="module"></script>
4241

43-
44-
45-
46-
47-
48-
49-
<!-- <script src="../static/TESTING.js"></script> -->
5042
</body>
5143

5244
</html>

0 commit comments

Comments
 (0)