Compare commits
5 Commits
debian12fu
...
developmen
Author | SHA1 | Date | |
---|---|---|---|
20bee1018c | |||
f32ddd837b | |||
38ef97b553 | |||
ff77629a01 | |||
4c42bd94ea |
98
README.md
98
README.md
@@ -1,15 +1,95 @@
|
||||
# Weather App
|
||||
|
||||
This version is only meant for publishing on the web. It is not meant for local development or use.
|
||||
This is a simple weather application that allows users to view current weather data for a specified location. The app is built using React and TypeScript, and it fetches weather data from an external API.
|
||||
|
||||
You can find the web version of the Weather App at [https://weather.the1s.de](https://weather.the1s.de).
|
||||
> For that we use the OpenWeatherMap API. You can get your own API key by signing up at [OpenWeatherMap](https://openweathermap.org/api).
|
||||
|
||||
## Features
|
||||
|
||||
- Search for weather by city name
|
||||
- Display current weather conditions including temperature, humidity, and wind speed
|
||||
- Responsive design for mobile and desktop views
|
||||
- Change API key preferences
|
||||
- Display weather data in a user-friendly format
|
||||
|
||||
## Installation
|
||||
### Prerequisites
|
||||
|
||||
To install and run this application, you need the following tools:
|
||||
|
||||
- Git (for cloning the repository)
|
||||
|
||||
**and**
|
||||
|
||||
- Node.js (v14 or higher)
|
||||
- npm (Node Package Manager)
|
||||
|
||||
**or**
|
||||
|
||||
- Docker (for running the app in a container)
|
||||
|
||||
### 1st step - Get the source code
|
||||
**You can either clone the repository or download the latest release. Keep in mind that the cloned version may contain bugs.**
|
||||
1. Clone the repository:
|
||||
```bash
|
||||
git clone https://git.the1s.de/theis.gaedigk/weather-app.git
|
||||
```
|
||||
|
||||
**or**
|
||||
|
||||
1. Download the latest release from the [releases page](https://git.the1s.de/theis.gaedigk/weather-app/releases/latest).
|
||||
2. Unzip the downloaded file to your desired location.
|
||||
|
||||
#### 2nd step - Using Node.js and npm
|
||||
|
||||
1. Navigate to the frontend project directory:
|
||||
```bash
|
||||
cd weather-app/frontend
|
||||
```
|
||||
2. Install dependencies:
|
||||
```bash
|
||||
npm install
|
||||
```
|
||||
3. Start the development server:
|
||||
```bash
|
||||
npm run dev
|
||||
```
|
||||
4. Open your browser and go to `http://localhost:7002` to view the app.
|
||||
**Note:** There is also a backend server directory, which is currently not in use. - You can ignore it for now.
|
||||
|
||||
**or**
|
||||
|
||||
#### 2nd step - Using Docker
|
||||
|
||||
1. Navigate to the root path project directory:
|
||||
```bash
|
||||
cd weather-app
|
||||
```
|
||||
2. Run in a Docker container:
|
||||
```bash
|
||||
docker compose up -d --build
|
||||
```
|
||||
3. Open your browser and go to `http://localhost:7002` to view the app.
|
||||
**Note:** There is also a backend server directory, which is currently not in use. - You can ignore it for now.
|
||||
|
||||
## Usage
|
||||
|
||||
1. Get an API key from [OpenWeatherMap](https://openweathermap.org/api).
|
||||
2. Click on the "Set API Key" button in the header to enter your API key.
|
||||
3. Enter a city name in the search bar and press Enter or click the "Get Weather" button.
|
||||
|
||||
**Now you can view the current weather data for the specified city!**
|
||||
|
||||
# Other Information
|
||||
|
||||
## Technologies Used
|
||||
|
||||
- React
|
||||
- TypeScript
|
||||
- Tailwind CSS
|
||||
- OpenWeatherMap API
|
||||
- Vite
|
||||
|
||||
## Version
|
||||
|
||||
Currently hosted version: **1.0.1**
|
||||
|
||||
## Dev info
|
||||
|
||||
All changes that are made to this branch (`debian12`) will be automatically deployed to the [web version](https://weather.the1s.de) of the Weather App.
|
||||
|
||||
This is done by using an auto pull script (`auto-pull.sh`) that runs on the server where the web version is hosted.
|
||||
**On this branch (main) you will find the latest version of the weather app, which includes several improvements and bug fixes. But it is not yet fully functional. The app is still in development, and some features may not work as expected.**
|
||||
|
9
RELEASE_NOTES.md
Normal file
9
RELEASE_NOTES.md
Normal file
@@ -0,0 +1,9 @@
|
||||
## Release Notes
|
||||
|
||||
### New Features
|
||||
- Changed **web panel** backend, so you don't need to set the API key anymore. [Web Panel](https://weather.the1s.de)
|
||||
- You can now see the **last updated** time in the web panel.
|
||||
|
||||
### Improvements
|
||||
- Changed Website Icons to lucide react icons
|
||||
- Changed overall handling of the panel
|
@@ -1,6 +0,0 @@
|
||||
#!/bin/bash
|
||||
cd /pfad/zu/deinem/repo
|
||||
while true; do
|
||||
git pull || echo "git pull failed"
|
||||
sleep 10
|
||||
done
|
@@ -1,63 +0,0 @@
|
||||
import { Router } from "express";
|
||||
import dotenv from "dotenv";
|
||||
|
||||
const router = Router();
|
||||
dotenv.config();
|
||||
|
||||
router.get("/fetchWeather", async (req, res) => {
|
||||
const city = req.query.city;
|
||||
const units = req.query.units;
|
||||
const apiKey = process.env.API_KEY;
|
||||
|
||||
try {
|
||||
const locationResponse = await fetch(
|
||||
`https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||
);
|
||||
if (!locationResponse.ok) {
|
||||
return res.status(404).json({
|
||||
error: "Error fetching location data. (Error: x32)",
|
||||
success: "false",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
const location = await locationResponse.json();
|
||||
if (!location || !location[0]) {
|
||||
return res.status(404).json({
|
||||
error: "Location not found.",
|
||||
success: "false",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const lat = location[0].lat;
|
||||
const lon = location[0].lon;
|
||||
|
||||
const weatherResponse = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}&units=${units}`
|
||||
);
|
||||
|
||||
if (!weatherResponse.ok) {
|
||||
return res.status(500).json({
|
||||
error: "Unexpected error! (Error: x33)",
|
||||
success: "false",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
|
||||
const weather = await weatherResponse.json();
|
||||
|
||||
res.status(200).json({
|
||||
error: "false",
|
||||
success: "Weather data fetched successfully!",
|
||||
data: weather,
|
||||
});
|
||||
} catch (err) {
|
||||
res.status(500).json({
|
||||
error: "Server error",
|
||||
success: "false",
|
||||
data: null,
|
||||
});
|
||||
}
|
||||
});
|
||||
|
||||
export default router;
|
@@ -1,7 +1,7 @@
|
||||
import express from "express";
|
||||
import cors from "cors";
|
||||
import apiRouter from "./routes/api.js";
|
||||
|
||||
import env from "dotenv";
|
||||
env.config();
|
||||
const app = express();
|
||||
const port = 7001;
|
||||
|
||||
@@ -10,8 +10,6 @@ app.use(express.urlencoded({ extended: true }));
|
||||
app.set("view engine", "ejs");
|
||||
app.use(express.json());
|
||||
|
||||
app.use("/api", apiRouter);
|
||||
|
||||
app.get("/", (req, res) => {
|
||||
res.render("index.ejs", { title: port });
|
||||
});
|
||||
|
@@ -1,12 +1,11 @@
|
||||
<!DOCTYPE html>
|
||||
<html lang="en">
|
||||
<head>
|
||||
<meta charset="UTF-8" />
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
|
||||
<meta charset="UTF-8">
|
||||
<meta name="viewport" content="width=device-width, initial-scale=1.0">
|
||||
<title>Backend | <%= title %></title>
|
||||
</head>
|
||||
<body>
|
||||
<h1>You have reached the backend views index page!</h1>
|
||||
<p>Currently, there is nothing to display!</p>
|
||||
You have reached the backend views index page.
|
||||
</body>
|
||||
</html>
|
@@ -1,26 +1,20 @@
|
||||
services:
|
||||
# frontend:
|
||||
# container_name: weather-frontend
|
||||
# build: ./frontend
|
||||
# ports:
|
||||
# - "7002:7002"
|
||||
# # networks:
|
||||
# # - proxynet
|
||||
# environment:
|
||||
# - CHOKIDAR_USEPOLLING=true
|
||||
# volumes:
|
||||
# - ./frontend:/app
|
||||
# - /app/node_modules
|
||||
# restart: unless-stopped
|
||||
backend:
|
||||
container_name: weather-backend
|
||||
build: ./backend
|
||||
frontend:
|
||||
container_name: frontend
|
||||
build: ./frontend
|
||||
ports:
|
||||
- "7001:7001"
|
||||
- "7002:7002"
|
||||
environment:
|
||||
- CHOKIDAR_USEPOLLING=true
|
||||
volumes:
|
||||
- ./backend:/app
|
||||
- ./frontend:/app
|
||||
- /app/node_modules
|
||||
restart: unless-stopped
|
||||
#networks:
|
||||
# proxynet:
|
||||
# external: true
|
||||
# backend:
|
||||
# container_name: backend
|
||||
# build: ./backend
|
||||
# ports:
|
||||
# - "7001:7001"
|
||||
#volumes:
|
||||
# - ./backend:/bikelane-backend
|
||||
# restart: unless-stopped
|
||||
|
@@ -53,7 +53,7 @@ const ChangeAPI: React.FC<Props> = ({ currentAPIKey, onClose }) => {
|
||||
</div>
|
||||
<button
|
||||
type="submit"
|
||||
className="bg-gradient-to-r from-blue-600 to-blue-400 text-white font-bold px-6 py-3 rounded-xl shadow-lg hover:from-blue-700 hover:to-blue-500 transition-all"
|
||||
className="cursor-pointer bg-gradient-to-r from-blue-600 to-blue-400 text-white font-bold px-6 py-3 rounded-xl shadow-lg hover:from-blue-700 hover:to-blue-500 transition-all"
|
||||
onClick={handleUpdate}
|
||||
>
|
||||
Update API Key
|
||||
|
@@ -58,7 +58,7 @@ const ChangePreferences: React.FC<Props> = ({ onClose }) => {
|
||||
</div>
|
||||
{/* Theme */}
|
||||
<div>
|
||||
<label className="cursor-pointer block text-sm font-semibold text-gray-700 mb-2 items-center gap-2">
|
||||
<label className="block text-sm font-semibold text-gray-700 mb-2 items-center gap-2">
|
||||
<SunMoon />
|
||||
Theme
|
||||
</label>
|
||||
|
@@ -1,7 +1,6 @@
|
||||
import React from "react";
|
||||
import ChangeAPI from "./ChangeAPI";
|
||||
import ChangePreferences from "./ChangePreferences";
|
||||
import { myToast } from "../utils/toastify";
|
||||
import { useState } from "react";
|
||||
import Cookies from "js-cookie";
|
||||
import logo from "../assets/cloud-sun-fill.png";
|
||||
@@ -22,15 +21,15 @@ const Header: React.FC = () => {
|
||||
className="w-10 h-10 drop-shadow-lg"
|
||||
/>
|
||||
<h1 className="text-4xl font-extrabold tracking-wide drop-shadow-lg">
|
||||
Weather App - <strong>Web</strong>
|
||||
Weather App - <strong>Local hosted</strong>
|
||||
</h1>
|
||||
</div>
|
||||
<div className="flex items-center gap-4">
|
||||
{" "}
|
||||
{/* Added container for buttons */}
|
||||
<button
|
||||
className="bg-gray-200 text-gray-400 font-bold px-6 py-3 rounded-xl shadow-lg border border-gray-300 flex items-center gap-2 cursor-not-allowed opacity-60"
|
||||
onClick={() => myToast("You don't need to set an API Key!", "info")}
|
||||
className="cursor-pointer bg-white text-blue-700 font-bold px-6 py-3 rounded-xl shadow-lg hover:bg-blue-100 transition-all border border-blue-200 flex items-center gap-2"
|
||||
onClick={() => setApiCard(true)}
|
||||
>
|
||||
<span className="flex items-center gap-2">
|
||||
<KeyRound />
|
||||
|
@@ -1,5 +1,6 @@
|
||||
import React from "react";
|
||||
import { Sunrise, Sunset } from "lucide-react";
|
||||
import { getDateTime } from "../utils/utils";
|
||||
|
||||
const WeatherData: React.FC = () => {
|
||||
const weatherRaw = localStorage.getItem("weather");
|
||||
@@ -75,6 +76,11 @@ const WeatherData: React.FC = () => {
|
||||
: "--:--"}
|
||||
</span>
|
||||
</div>
|
||||
<div className="flex items-center gap-3">
|
||||
<span className="text-base text-gray-600 italic font-semibold">
|
||||
Last updated: {getDateTime()}
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
@@ -1,6 +1,7 @@
|
||||
import React from "react";
|
||||
import { useState } from "react";
|
||||
import { fetchWeather } from "../utils/apiFunc";
|
||||
import Cookies from "js-cookie";
|
||||
import { toast } from "react-toastify";
|
||||
import WeatherData from "./WeatherData";
|
||||
import { useEffect } from "react";
|
||||
@@ -9,6 +10,7 @@ import { X } from "lucide-react";
|
||||
const WeatherCard: React.FC = () => {
|
||||
const [city, setCity] = useState("");
|
||||
const [weatherData, setWeatherData] = useState(false);
|
||||
const getAPIKey = () => Cookies.get("apiKey") || "";
|
||||
const getUnit = () => localStorage.getItem("unit") || "metric";
|
||||
|
||||
const handleCityChange = (event: React.ChangeEvent<HTMLInputElement>) => {
|
||||
@@ -17,13 +19,10 @@ const WeatherCard: React.FC = () => {
|
||||
|
||||
const handleSubmit = async (event: React.FormEvent<HTMLFormElement>) => {
|
||||
event.preventDefault();
|
||||
setWeatherData(false);
|
||||
toast
|
||||
.promise(fetchWeather(city, getUnit()), {
|
||||
.promise(fetchWeather(city, getAPIKey(), getUnit()), {
|
||||
pending: "Fetching weather data...",
|
||||
success: "Weather data loaded successfully!",
|
||||
error:
|
||||
"Failed to load weather data. Please check your entered city name. (Error: x4040)",
|
||||
})
|
||||
.then(() => {
|
||||
if (localStorage.getItem("weather")) {
|
||||
@@ -52,7 +51,7 @@ const WeatherCard: React.FC = () => {
|
||||
Current weather will be displayed here.
|
||||
</p>
|
||||
<p className="mb-2 text-gray-600">
|
||||
<strong>You don't need an API Key!</strong>
|
||||
<strong>Make sure to set your API key in the header section.</strong>
|
||||
</p>
|
||||
<form onSubmit={handleSubmit} className="flex flex-col gap-4 mt-4">
|
||||
<label htmlFor="city" className="font-medium text-gray-700">
|
||||
@@ -68,7 +67,7 @@ const WeatherCard: React.FC = () => {
|
||||
required
|
||||
className="border border-blue-300 rounded-xl px-4 py-3 focus:outline-none focus:ring-2 focus:ring-blue-400 bg-blue-50 text-blue-900 font-mono"
|
||||
/>
|
||||
<div className="cursor-pointer flex items-center gap-2">
|
||||
<div className="flex items-center gap-2">
|
||||
<button
|
||||
type="submit"
|
||||
className="cursor-pointer flex-1 bg-gradient-to-r from-blue-600 to-blue-400 text-white font-bold px-4 py-3 rounded-xl shadow-lg hover:from-blue-700 hover:to-blue-500 transition-all"
|
||||
|
@@ -1,30 +1,36 @@
|
||||
import { myToast } from "./toastify";
|
||||
import Cookies from "js-cookie";
|
||||
|
||||
export const fetchWeather = async (city: string, units: string) => {
|
||||
try {
|
||||
const response = await fetch(
|
||||
`http://localhost:7001/api/fetchWeather?city=${encodeURIComponent(
|
||||
city
|
||||
)}&units=${encodeURIComponent(units)}`,
|
||||
{
|
||||
method: "GET",
|
||||
headers: {
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
}
|
||||
export const fetchWeather = async (
|
||||
city: string,
|
||||
apiKey: string,
|
||||
units: string
|
||||
) => {
|
||||
// Get location data
|
||||
const location = await fetch(
|
||||
`http://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||
).then((response) => {
|
||||
if (response.status === 401) {
|
||||
if (Cookies.get("apiKey") === undefined || Cookies.get("apiKey") === "") {
|
||||
myToast("You have to enter an API key!", "error");
|
||||
} else {
|
||||
myToast(
|
||||
"You are not authorized to access this resource. Please check your API key. (Error: x4010)",
|
||||
"error"
|
||||
);
|
||||
|
||||
const responseData = await response.json();
|
||||
|
||||
if (!response.ok) {
|
||||
myToast(responseData.error, "error");
|
||||
return;
|
||||
}
|
||||
localStorage.setItem("weather", JSON.stringify(responseData.data));
|
||||
return;
|
||||
} catch (error) {
|
||||
const errorMsg = JSON.stringify(error);
|
||||
myToast(errorMsg, "error");
|
||||
return null;
|
||||
} else if (response.ok) {
|
||||
return response.json();
|
||||
} else {
|
||||
myToast("Error fetching location data. (Error: x32)", "error");
|
||||
}
|
||||
});
|
||||
const lat = location[0].lat;
|
||||
const lon = location[0].lon;
|
||||
|
||||
// Get weather data
|
||||
const weather = await fetch(
|
||||
`https://api.openweathermap.org/data/2.5/weather?lat=${lat}&lon=${lon}&appid=${apiKey}&units=${units}`
|
||||
).then((response) => response.json());
|
||||
localStorage.setItem("weather", JSON.stringify(weather));
|
||||
};
|
||||
|
24
frontend/src/utils/utils.ts
Normal file
24
frontend/src/utils/utils.ts
Normal file
@@ -0,0 +1,24 @@
|
||||
export const getDateTime = () => {
|
||||
const now = new Date();
|
||||
const day = now.getDate();
|
||||
const month = now.toLocaleString("en-GB", { month: "long" });
|
||||
const hours = now.getHours().toString().padStart(2, "0");
|
||||
const minutes = now.getMinutes().toString().padStart(2, "0");
|
||||
|
||||
// Ordinal suffix
|
||||
const getOrdinal = (n: number) => {
|
||||
if (n > 3 && n < 21) return "th";
|
||||
switch (n % 10) {
|
||||
case 1:
|
||||
return "st";
|
||||
case 2:
|
||||
return "nd";
|
||||
case 3:
|
||||
return "rd";
|
||||
default:
|
||||
return "th";
|
||||
}
|
||||
};
|
||||
|
||||
return `${day}${getOrdinal(day)} ${month}, ${hours}:${minutes}`;
|
||||
};
|
Reference in New Issue
Block a user