fix: weather modal, remove tasks/savings, fix HA controls, safe-area BottomNav
All checks were successful
Deploy to Coolify / deploy (push) Successful in 3s
All checks were successful
Deploy to Coolify / deploy (push) Successful in 3s
This commit is contained in:
@@ -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 };
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user