fix: weather modal, remove tasks/savings, fix HA controls, safe-area BottomNav
All checks were successful
Deploy to Coolify / deploy (push) Successful in 3s

This commit is contained in:
Cosmo
2026-04-22 10:42:41 +00:00
parent a2fb233363
commit 98fdcafb73
6 changed files with 220 additions and 162 deletions

View File

@@ -1,10 +1,9 @@
"use client";
import { useState, useEffect, useCallback } from "react";
import { HAStates } from "@/lib/ha";
export function useHA(refreshInterval = 10000) {
const [data, setData] = useState<HAStates | null>(null);
const [data, setData] = useState<any>(null);
const [loading, setLoading] = useState(true);
const refresh = useCallback(async () => {
@@ -31,26 +30,34 @@ export function useHA(refreshInterval = 10000) {
export function useWeather() {
const [weather, setWeather] = useState<any>(null);
useEffect(() => {
fetch("/api/weather")
.then((r) => r.json())
.then(setWeather)
.catch(() => {});
const fetchWeather = useCallback(async () => {
try {
const res = await fetch("/api/weather", { cache: "no-store" });
const json = await res.json();
setWeather(json);
} catch (e) {
setWeather({ temp: "—", desc: "Нет данных", weatherCode: "116", forecast: [] });
}
}, []);
useEffect(() => {
fetchWeather();
// Refresh every 10 minutes
const id = setInterval(fetchWeather, 10 * 60 * 1000);
return () => clearInterval(id);
}, [fetchWeather]);
return weather;
}
export function useTasks() {
const [tasks, setTasks] = useState<any[]>([]);
const [demo, setDemo] = useState(false);
const refresh = useCallback(async () => {
try {
const res = await fetch("/api/tasks", { cache: "no-store" });
const json = await res.json();
setTasks(json.tasks || []);
setDemo(!!json.demo);
} catch (e) {}
}, []);
@@ -58,22 +65,5 @@ export function useTasks() {
refresh();
}, [refresh]);
return { tasks, setTasks, demo, refresh };
}
export function useSavings() {
const [savings, setSavings] = useState<any[]>([]);
const [demo, setDemo] = useState(false);
useEffect(() => {
fetch("/api/savings")
.then((r) => r.json())
.then((d) => {
setSavings(d.savings || []);
setDemo(!!d.demo);
})
.catch(() => {});
}, []);
return { savings, demo };
return { tasks, setTasks, refresh };
}