Compare commits
7 Commits
debian12fu
...
debian12
Author | SHA1 | Date | |
---|---|---|---|
9b0f7daa2c | |||
0361a743ef | |||
f70629fa55 | |||
d84d876735 | |||
574f094bac | |||
71da186bd6 | |||
4f98bf4e9a |
@@ -6,7 +6,7 @@ You can find the web version of the Weather App at [https://weather.the1s.de](ht
|
|||||||
|
|
||||||
## Version
|
## Version
|
||||||
|
|
||||||
Currently hosted version: **1.0.1**
|
Currently hosted version: **development branch (latest)**
|
||||||
|
|
||||||
## Dev info
|
## Dev info
|
||||||
|
|
||||||
|
@@ -14,7 +14,7 @@ router.get("/fetchWeather", async (req, res) => {
|
|||||||
`https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
`https://api.openweathermap.org/geo/1.0/direct?q=${city}&appid=${apiKey}`
|
||||||
);
|
);
|
||||||
if (!locationResponse.ok) {
|
if (!locationResponse.ok) {
|
||||||
return res.status(404).json({
|
return res.status(500).json({
|
||||||
error: "Error fetching location data. (Error: x32)",
|
error: "Error fetching location data. (Error: x32)",
|
||||||
success: "false",
|
success: "false",
|
||||||
data: null,
|
data: null,
|
||||||
|
@@ -1,26 +1,29 @@
|
|||||||
services:
|
services:
|
||||||
# frontend:
|
frontend:
|
||||||
# container_name: weather-frontend
|
container_name: weather-frontend
|
||||||
# build: ./frontend
|
build: ./frontend
|
||||||
# ports:
|
ports:
|
||||||
# - "7002:7002"
|
- "7002:7002"
|
||||||
# # networks:
|
networks:
|
||||||
# # - proxynet
|
- proxynet
|
||||||
# environment:
|
environment:
|
||||||
# - CHOKIDAR_USEPOLLING=true
|
- CHOKIDAR_USEPOLLING=true
|
||||||
# volumes:
|
volumes:
|
||||||
# - ./frontend:/app
|
- ./frontend:/app
|
||||||
# - /app/node_modules
|
- /app/node_modules
|
||||||
# restart: unless-stopped
|
restart: unless-stopped
|
||||||
backend:
|
backend:
|
||||||
container_name: weather-backend
|
container_name: weather-backend
|
||||||
build: ./backend
|
build: ./backend
|
||||||
|
networks:
|
||||||
|
- proxynet
|
||||||
ports:
|
ports:
|
||||||
- "7001:7001"
|
- "7001:7001"
|
||||||
volumes:
|
volumes:
|
||||||
- ./backend:/app
|
- ./backend:/app
|
||||||
- /app/node_modules
|
- /app/node_modules
|
||||||
restart: unless-stopped
|
restart: unless-stopped
|
||||||
#networks:
|
|
||||||
# proxynet:
|
networks:
|
||||||
# external: true
|
proxynet:
|
||||||
|
external: true
|
||||||
|
@@ -1,5 +1,6 @@
|
|||||||
import React from "react";
|
import React from "react";
|
||||||
import { Sunrise, Sunset } from "lucide-react";
|
import { Sunrise, Sunset } from "lucide-react";
|
||||||
|
import { getDateTime } from "../utils/utils";
|
||||||
|
|
||||||
const WeatherData: React.FC = () => {
|
const WeatherData: React.FC = () => {
|
||||||
const weatherRaw = localStorage.getItem("weather");
|
const weatherRaw = localStorage.getItem("weather");
|
||||||
@@ -75,6 +76,11 @@ const WeatherData: React.FC = () => {
|
|||||||
: "--:--"}
|
: "--:--"}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</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>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
|
@@ -21,9 +21,6 @@ const WeatherCard: React.FC = () => {
|
|||||||
toast
|
toast
|
||||||
.promise(fetchWeather(city, getUnit()), {
|
.promise(fetchWeather(city, getUnit()), {
|
||||||
pending: "Fetching weather data...",
|
pending: "Fetching weather data...",
|
||||||
success: "Weather data loaded successfully!",
|
|
||||||
error:
|
|
||||||
"Failed to load weather data. Please check your entered city name. (Error: x4040)",
|
|
||||||
})
|
})
|
||||||
.then(() => {
|
.then(() => {
|
||||||
if (localStorage.getItem("weather")) {
|
if (localStorage.getItem("weather")) {
|
||||||
|
@@ -3,7 +3,7 @@ import { myToast } from "./toastify";
|
|||||||
export const fetchWeather = async (city: string, units: string) => {
|
export const fetchWeather = async (city: string, units: string) => {
|
||||||
try {
|
try {
|
||||||
const response = await fetch(
|
const response = await fetch(
|
||||||
`http://localhost:7001/api/fetchWeather?city=${encodeURIComponent(
|
`https://backend.weather.the1s.de/api/fetchWeather?city=${encodeURIComponent(
|
||||||
city
|
city
|
||||||
)}&units=${encodeURIComponent(units)}`,
|
)}&units=${encodeURIComponent(units)}`,
|
||||||
{
|
{
|
||||||
@@ -21,6 +21,7 @@ export const fetchWeather = async (city: string, units: string) => {
|
|||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
localStorage.setItem("weather", JSON.stringify(responseData.data));
|
localStorage.setItem("weather", JSON.stringify(responseData.data));
|
||||||
|
myToast(responseData.success, "success");
|
||||||
return;
|
return;
|
||||||
} catch (error) {
|
} catch (error) {
|
||||||
const errorMsg = JSON.stringify(error);
|
const errorMsg = JSON.stringify(error);
|
||||||
|
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