Refactor code structure for improved readability and maintainability

This commit is contained in:
2025-08-01 19:43:11 +02:00
parent 8341e50dc8
commit 11e6e1684c
9 changed files with 22 additions and 9 deletions

View File

@@ -49,5 +49,4 @@ This is a simple weather application that allows users to view current weather d
- Vite - Vite
## Version ## Version
This project is currently in development. But will be updated regularly and is expected to be stable soon. **1.0.0**
> There is also coming a public version of the app, which will be hosted on a server. - **Stay tuned for updates!**

View File

@@ -5,7 +5,7 @@
<link <link
rel="icon" rel="icon"
type="image/svg+xml" type="image/svg+xml"
href="./src/assets/cloud-sun-fill.svg" href="./src/assets/cloud-sun-fill.png"
/> />
<meta name="viewport" content="width=device-width, initial-scale=1.0" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" />
<title>Weather App</title> <title>Weather App</title>

Binary file not shown.

After

Width:  |  Height:  |  Size: 24 KiB

Binary file not shown.

Binary file not shown.

View File

@@ -3,7 +3,7 @@ import ChangeAPI from "./ChangeAPI";
import ChangePreferences from "./ChangePreferences"; import ChangePreferences from "./ChangePreferences";
import { useState } from "react"; import { useState } from "react";
import Cookies from "js-cookie"; import Cookies from "js-cookie";
import logo from "../assets/cloud-sun-fill.svg"; import logo from "../assets/cloud-sun-fill.png";
const Header: React.FC = () => { const Header: React.FC = () => {
const [apiCard, setApiCard] = useState(false); const [apiCard, setApiCard] = useState(false);
@@ -76,7 +76,7 @@ const Header: React.FC = () => {
</span> </span>
</button> </button>
<a <a
href="https://git.the1s.de/theis.gaedigk/weather-app/wiki" href="https://github.com/theis-js/weather-app/wiki"
target="_blank" target="_blank"
rel="noopener noreferrer" rel="noopener noreferrer"
> >

View File

@@ -25,7 +25,7 @@ const WeatherCard: React.FC = () => {
pending: "Fetching weather data...", pending: "Fetching weather data...",
success: "Weather data loaded successfully!", success: "Weather data loaded successfully!",
error: error:
"Failed to load weather data. Please check your entered city name.", "Failed to load weather data. Please check your entered city name. (Error: x4040)",
}) })
.then(() => { .then(() => {
if (localStorage.getItem("weather")) { if (localStorage.getItem("weather")) {

View File

@@ -10,11 +10,14 @@ export const fetchWeather = async (
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}` `http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
).then((response) => { ).then((response) => {
if (response.status === 401) { if (response.status === 401) {
myToast("You are not authorized to access this resource. Please check your API key.", "error"); myToast(
"You are not authorized to access this resource. Please check your API key. (Error: x4010)",
"error"
);
} else if (response.ok) { } else if (response.ok) {
return response.json(); return response.json();
} else { } else {
myToast("Error fetching location data: " + response.statusText, "error"); myToast("Error fetching location data. (Error: x32)", "error");
} }
}); });
const lat = location[0].lat; const lat = location[0].lat;

View File

@@ -4,5 +4,16 @@ import { myToast } from "./toastify";
export const changeAPIcookie = (newApiKey: string) => { export const changeAPIcookie = (newApiKey: string) => {
let apiKey15 = newApiKey.slice(0, 15); let apiKey15 = newApiKey.slice(0, 15);
Cookies.set("apiKey", newApiKey); Cookies.set("apiKey", newApiKey);
myToast("API key updated successfully!" + " " + "Your new API key: " + apiKey15 + "...", "success"); if (Cookies.get("apiKey") === newApiKey) {
myToast(
"API key updated successfully!" +
" " +
"Your new API key: " +
apiKey15 +
"...",
"success"
);
} else {
myToast("Failed to update API key. (Error: x30)", "error");
}
}; };