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:
@@ -4,22 +4,22 @@ import { NextRequest, NextResponse } from "next/server";
|
||||
const HA_URL = process.env.HA_URL || "http://192.168.31.110:8123";
|
||||
const HA_TOKEN = process.env.HA_TOKEN || "";
|
||||
|
||||
// Real entity IDs → normalized keys used in the dashboard
|
||||
const REAL_ENTITY_ALIASES: Record<string, string> = {
|
||||
"fan.zhimi_rmb1_9528_air_purifier": "fan.air_purifier",
|
||||
};
|
||||
|
||||
// Mock data for entities that don't exist yet (квартира строится)
|
||||
const MOCK_MISSING: Record<string, any> = {
|
||||
"light.living_room": {
|
||||
entity_id: "light.living_room",
|
||||
state: "off",
|
||||
attributes: { brightness: 0, friendly_name: "Свет Гостиная" },
|
||||
_mock: true,
|
||||
},
|
||||
"light.bedroom": {
|
||||
entity_id: "light.bedroom",
|
||||
state: "off",
|
||||
attributes: { friendly_name: "Свет Спальня" },
|
||||
_mock: true,
|
||||
},
|
||||
"climate.thermostat": {
|
||||
entity_id: "climate.thermostat",
|
||||
@@ -29,15 +29,17 @@ const MOCK_MISSING: Record<string, any> = {
|
||||
temperature: 22,
|
||||
friendly_name: "Термостат",
|
||||
},
|
||||
_mock: true,
|
||||
},
|
||||
"fan.air_purifier": {
|
||||
entity_id: "fan.air_purifier",
|
||||
state: "on",
|
||||
state: "off",
|
||||
attributes: {
|
||||
preset_mode: "Auto",
|
||||
friendly_name: "Очиститель воздуха",
|
||||
preset_modes: ["Auto", "Night", "High"],
|
||||
},
|
||||
_mock: true,
|
||||
},
|
||||
};
|
||||
|
||||
@@ -59,20 +61,23 @@ export async function GET(req: NextRequest) {
|
||||
Authorization: `Bearer ${HA_TOKEN}`,
|
||||
"Content-Type": "application/json",
|
||||
},
|
||||
next: { revalidate: 0 },
|
||||
cache: "no-store",
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error(`HA responded ${res.status}`);
|
||||
const states: any[] = await res.json();
|
||||
|
||||
// Build filtered map with normalized keys
|
||||
const filtered: Record<string, any> = {};
|
||||
|
||||
// Get real temperature from air purifier sensor
|
||||
const tempSensor = states.find(s => s.entity_id === "sensor.zhimi_rmb1_9528_temperature");
|
||||
const humiditySensor = states.find(s => s.entity_id === "sensor.zhimi_rmb1_9528_relative_humidity");
|
||||
const pm25Sensor = states.find(s => s.entity_id === "sensor.zhimi_rmb1_9528_pm25_density");
|
||||
|
||||
for (const s of states) {
|
||||
// Direct match
|
||||
if (RELEVANT_KEYS.includes(s.entity_id)) {
|
||||
filtered[s.entity_id] = s;
|
||||
}
|
||||
// Alias match (real entity → normalized key)
|
||||
if (REAL_ENTITY_ALIASES[s.entity_id]) {
|
||||
const normalizedKey = REAL_ENTITY_ALIASES[s.entity_id];
|
||||
filtered[normalizedKey] = {
|
||||
@@ -83,31 +88,48 @@ export async function GET(req: NextRequest) {
|
||||
}
|
||||
}
|
||||
|
||||
// Fill in missing entities with mock data (but mark them)
|
||||
// Fill missing with mock
|
||||
for (const key of RELEVANT_KEYS) {
|
||||
if (!filtered[key]) {
|
||||
filtered[key] = { ...MOCK_MISSING[key], _mock: true };
|
||||
filtered[key] = { ...MOCK_MISSING[key] };
|
||||
}
|
||||
}
|
||||
|
||||
// demo = true only if ALL entities are mock (no real HA devices connected)
|
||||
// Inject real temperature into thermostat card if sensor exists
|
||||
if (tempSensor && filtered["climate.thermostat"]) {
|
||||
filtered["climate.thermostat"].attributes = {
|
||||
...filtered["climate.thermostat"].attributes,
|
||||
current_temperature: parseFloat(tempSensor.state),
|
||||
humidity: humiditySensor ? parseFloat(humiditySensor.state) : null,
|
||||
pm25: pm25Sensor ? parseFloat(pm25Sensor.state) : null,
|
||||
};
|
||||
}
|
||||
|
||||
const hasAnyReal = RELEVANT_KEYS.some(k => !filtered[k]?._mock);
|
||||
|
||||
return NextResponse.json({ demo: !hasAnyReal, states: filtered });
|
||||
return NextResponse.json({
|
||||
demo: !hasAnyReal,
|
||||
states: filtered,
|
||||
sensors: {
|
||||
temperature: tempSensor ? parseFloat(tempSensor.state) : null,
|
||||
humidity: humiditySensor ? parseFloat(humiditySensor.state) : null,
|
||||
pm25: pm25Sensor ? parseFloat(pm25Sensor.state) : null,
|
||||
}
|
||||
});
|
||||
} catch (e) {
|
||||
// Fallback to full mock
|
||||
return NextResponse.json({ demo: true, states: MOCK_MISSING });
|
||||
}
|
||||
}
|
||||
|
||||
export async function POST(req: NextRequest) {
|
||||
const { domain, service, entity_id, ...serviceData } = await req.json();
|
||||
const body = await req.json();
|
||||
const { domain, service, entity_id, ...serviceData } = body;
|
||||
|
||||
if (!HA_TOKEN) {
|
||||
return NextResponse.json({ success: true, demo: true });
|
||||
}
|
||||
|
||||
// Resolve alias: if normalized key, find real entity
|
||||
// Resolve alias
|
||||
const realEntityId = Object.keys(REAL_ENTITY_ALIASES).find(
|
||||
k => REAL_ENTITY_ALIASES[k] === entity_id
|
||||
) || entity_id;
|
||||
@@ -122,9 +144,12 @@ export async function POST(req: NextRequest) {
|
||||
body: JSON.stringify({ entity_id: realEntityId, ...serviceData }),
|
||||
});
|
||||
|
||||
if (!res.ok) throw new Error(`HA responded ${res.status}`);
|
||||
if (!res.ok) {
|
||||
// Entity might not exist (mock) — return success anyway for local state
|
||||
return NextResponse.json({ success: true, mock: true });
|
||||
}
|
||||
return NextResponse.json({ success: true });
|
||||
} catch (e) {
|
||||
return NextResponse.json({ success: false, error: String(e) }, { status: 500 });
|
||||
return NextResponse.json({ success: true, mock: true });
|
||||
}
|
||||
}
|
||||
|
||||
@@ -235,3 +235,16 @@ input[type='range']::-moz-range-thumb {
|
||||
.no-scrollbar::-webkit-scrollbar {
|
||||
display: none;
|
||||
}
|
||||
|
||||
/* Safe area support for tablets/mobile */
|
||||
@supports (padding: max(0px)) {
|
||||
body {
|
||||
padding-bottom: env(safe-area-inset-bottom, 0px);
|
||||
}
|
||||
}
|
||||
|
||||
/* Ensure 100dvh works properly */
|
||||
.h-dvh {
|
||||
height: 100dvh;
|
||||
height: 100svh;
|
||||
}
|
||||
|
||||
19
app/page.tsx
19
app/page.tsx
@@ -7,10 +7,10 @@ import BottomNav from "@/components/BottomNav";
|
||||
import LightCard from "@/components/cards/LightCard";
|
||||
import TemperatureCard from "@/components/cards/TemperatureCard";
|
||||
import AirPurifierCard from "@/components/cards/AirPurifierCard";
|
||||
import TasksCard from "@/components/cards/TasksCard";
|
||||
|
||||
import WeatherCard from "@/components/cards/WeatherCard";
|
||||
import RoomsRow from "@/components/RoomsRow";
|
||||
import { useHA, useWeather, useTasks } from "@/hooks/useHA";
|
||||
import { useHA, useWeather } from "@/hooks/useHA";
|
||||
|
||||
// Stagger container variants
|
||||
const containerVariants = {
|
||||
@@ -30,7 +30,6 @@ export default function Home() {
|
||||
|
||||
const { data: haData, loading: haLoading, refresh: refreshHA } = useHA(15000);
|
||||
const weather = useWeather();
|
||||
const { tasks, refresh: refreshTasks } = useTasks();
|
||||
|
||||
// Apply theme to html element
|
||||
useEffect(() => {
|
||||
@@ -299,20 +298,6 @@ export default function Home() {
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* ═══════════════ TASKS TAB ═══════════════ */}
|
||||
{activeTab === "tasks" && (
|
||||
<motion.div
|
||||
key="tasks"
|
||||
className="h-full max-w-2xl mx-auto w-full"
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
exit={{ opacity: 0, y: -20 }}
|
||||
transition={{ duration: 0.25 }}
|
||||
>
|
||||
<TasksCard tasks={tasks} onUpdate={refreshTasks} />
|
||||
</motion.div>
|
||||
)}
|
||||
|
||||
{/* ═══════════════ SETTINGS TAB ═══════════════ */}
|
||||
{activeTab === "settings" && (
|
||||
<motion.div
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { motion } from "framer-motion";
|
||||
import { Home, Cpu, CheckSquare, Settings } from "lucide-react";
|
||||
import { Home, Cpu, Settings } from "lucide-react";
|
||||
|
||||
interface Props {
|
||||
active: string;
|
||||
@@ -11,14 +11,13 @@ interface Props {
|
||||
const TABS = [
|
||||
{ id: "home", label: "Главная", icon: Home, color: "#6366f1" },
|
||||
{ id: "devices", label: "Устройства", icon: Cpu, color: "#3b82f6" },
|
||||
{ id: "tasks", label: "Задачи", icon: CheckSquare, color: "#8b5cf6" },
|
||||
{ id: "settings", label: "Настройки", icon: Settings, color: "#10b981" },
|
||||
];
|
||||
|
||||
export default function BottomNav({ active, onChange }: Props) {
|
||||
return (
|
||||
<motion.div
|
||||
className="glass-card px-3 py-2 flex items-center justify-around no-select"
|
||||
className="glass-card px-3 py-2 flex items-center justify-around no-select flex-shrink-0"
|
||||
style={{ borderRadius: "20px" }}
|
||||
initial={{ opacity: 0, y: 20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
@@ -31,7 +30,7 @@ export default function BottomNav({ active, onChange }: Props) {
|
||||
<motion.button
|
||||
key={tab.id}
|
||||
onClick={() => onChange(tab.id)}
|
||||
className="flex flex-col items-center gap-1.5 px-8 py-2 rounded-2xl relative"
|
||||
className="flex flex-col items-center gap-1.5 px-10 py-2 rounded-2xl relative"
|
||||
whileTap={{ scale: 0.85 }}
|
||||
>
|
||||
{isActive && (
|
||||
@@ -46,15 +45,8 @@ export default function BottomNav({ active, onChange }: Props) {
|
||||
transition={{ type: "spring", stiffness: 450, damping: 30 }}
|
||||
/>
|
||||
)}
|
||||
<Icon
|
||||
size={22}
|
||||
color={isActive ? tab.color : "var(--text-secondary)"}
|
||||
strokeWidth={isActive ? 2 : 1.5}
|
||||
/>
|
||||
<span
|
||||
className="text-xs font-semibold"
|
||||
style={{ color: isActive ? tab.color : "var(--text-secondary)" }}
|
||||
>
|
||||
<Icon size={22} color={isActive ? tab.color : "var(--text-secondary)"} strokeWidth={isActive ? 2 : 1.5} />
|
||||
<span className="text-xs font-semibold" style={{ color: isActive ? tab.color : "var(--text-secondary)" }}>
|
||||
{tab.label}
|
||||
</span>
|
||||
</motion.button>
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
"use client";
|
||||
|
||||
import { useState, useEffect } from "react";
|
||||
import { motion } from "framer-motion";
|
||||
import { motion, AnimatePresence } from "framer-motion";
|
||||
import ThemeToggle from "./ThemeToggle";
|
||||
|
||||
function getWeatherEmoji(code: string): string {
|
||||
@@ -9,15 +9,22 @@ function getWeatherEmoji(code: string): string {
|
||||
if (c === 113) return "☀️";
|
||||
if (c === 116) return "⛅";
|
||||
if (c === 119 || c === 122) return "☁️";
|
||||
if (c >= 176 && c <= 182) return "🌦️";
|
||||
if (c >= 185 && c <= 200) return "🌧️";
|
||||
if (c >= 176 && c <= 300) return "🌧️";
|
||||
if (c >= 200 && c <= 210) return "⛈️";
|
||||
if (c >= 210 && c <= 260) return "❄️";
|
||||
if (c >= 260 && c <= 300) return "🌨️";
|
||||
if (c >= 300 && c <= 400) return "🌧️";
|
||||
return "🌤️";
|
||||
}
|
||||
|
||||
function getDayName(dateStr: string): string {
|
||||
const d = new Date(dateStr + "T12:00:00");
|
||||
const today = new Date();
|
||||
const tomorrow = new Date(today);
|
||||
tomorrow.setDate(today.getDate() + 1);
|
||||
if (d.toDateString() === today.toDateString()) return "Сег";
|
||||
if (d.toDateString() === tomorrow.toDateString()) return "Завт";
|
||||
return d.toLocaleDateString("ru-RU", { weekday: "short" });
|
||||
}
|
||||
|
||||
interface Props {
|
||||
isDark: boolean;
|
||||
onToggleTheme: () => void;
|
||||
@@ -28,107 +35,153 @@ interface Props {
|
||||
export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props) {
|
||||
const [time, setTime] = useState("");
|
||||
const [date, setDate] = useState("");
|
||||
const [showModal, setShowModal] = useState(false);
|
||||
|
||||
useEffect(() => {
|
||||
const update = () => {
|
||||
const now = new Date();
|
||||
setTime(
|
||||
now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })
|
||||
);
|
||||
setDate(
|
||||
now.toLocaleDateString("ru-RU", {
|
||||
weekday: "short",
|
||||
day: "numeric",
|
||||
month: "long",
|
||||
})
|
||||
);
|
||||
setTime(now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" }));
|
||||
setDate(now.toLocaleDateString("ru-RU", { weekday: "short", day: "numeric", month: "long" }));
|
||||
};
|
||||
update();
|
||||
const id = setInterval(update, 1000);
|
||||
return () => clearInterval(id);
|
||||
}, []);
|
||||
|
||||
const hasWeather = weather && weather.temp && weather.temp !== "—";
|
||||
|
||||
return (
|
||||
<motion.div
|
||||
className="glass-card px-6 py-3 flex items-center justify-between no-select flex-shrink-0"
|
||||
style={{ borderRadius: "20px" }}
|
||||
initial={{ opacity: 0, y: -20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5 }}
|
||||
>
|
||||
{/* Time & Date */}
|
||||
<div className="flex items-baseline gap-4">
|
||||
<span
|
||||
className="font-black tracking-tight leading-none"
|
||||
style={{ fontSize: "42px", color: "var(--text-primary)" }}
|
||||
>
|
||||
{time}
|
||||
</span>
|
||||
<span
|
||||
className="text-sm font-medium capitalize"
|
||||
style={{ color: "var(--text-secondary)" }}
|
||||
>
|
||||
{date}
|
||||
</span>
|
||||
</div>
|
||||
|
||||
{/* Weather pill */}
|
||||
{weather && weather.temp !== "—" ? (
|
||||
<motion.div
|
||||
className="flex items-center gap-3 px-5 py-2 rounded-2xl"
|
||||
style={{
|
||||
background: "rgba(59,130,246,0.1)",
|
||||
border: "1px solid rgba(59,130,246,0.22)",
|
||||
}}
|
||||
initial={{ opacity: 0, scale: 0.9 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ delay: 0.3 }}
|
||||
>
|
||||
<span className="text-2xl leading-none">
|
||||
{getWeatherEmoji(weather.weatherCode)}
|
||||
<>
|
||||
<motion.div
|
||||
className="glass-card px-6 py-3 flex items-center justify-between no-select flex-shrink-0"
|
||||
style={{ borderRadius: "20px" }}
|
||||
initial={{ opacity: 0, y: -20 }}
|
||||
animate={{ opacity: 1, y: 0 }}
|
||||
transition={{ duration: 0.5 }}
|
||||
>
|
||||
{/* Time & Date */}
|
||||
<div className="flex items-baseline gap-4">
|
||||
<span className="font-black tracking-tight leading-none" style={{ fontSize: "42px", color: "var(--text-primary)" }}>
|
||||
{time}
|
||||
</span>
|
||||
<span className="text-sm font-medium capitalize" style={{ color: "var(--text-secondary)" }}>
|
||||
{date}
|
||||
</span>
|
||||
<div>
|
||||
<div
|
||||
className="text-xl font-black leading-tight"
|
||||
style={{ color: "var(--text-primary)" }}
|
||||
>
|
||||
{weather.temp}°C
|
||||
</div>
|
||||
<div
|
||||
className="text-xs leading-tight"
|
||||
style={{ color: "var(--text-secondary)" }}
|
||||
>
|
||||
{weather.desc}
|
||||
</div>
|
||||
</div>
|
||||
</motion.div>
|
||||
) : weather ? (
|
||||
<div
|
||||
className="text-sm px-4 py-2 rounded-2xl"
|
||||
style={{ color: "var(--text-secondary)", background: "rgba(255,255,255,0.04)" }}
|
||||
>
|
||||
🌤️ Загрузка...
|
||||
</div>
|
||||
) : null}
|
||||
|
||||
{/* Theme toggle + Demo badge */}
|
||||
<div className="flex items-center gap-3">
|
||||
{isDemo && (
|
||||
<motion.span
|
||||
className="text-xs px-2.5 py-1 rounded-full font-semibold"
|
||||
style={{
|
||||
background: "rgba(245,158,11,0.15)",
|
||||
color: "#f59e0b",
|
||||
border: "1px solid rgba(245,158,11,0.3)",
|
||||
}}
|
||||
{/* Weather pill — clickable */}
|
||||
{hasWeather ? (
|
||||
<motion.button
|
||||
className="flex items-center gap-3 px-5 py-2 rounded-2xl cursor-pointer"
|
||||
style={{ background: "rgba(59,130,246,0.1)", border: "1px solid rgba(59,130,246,0.22)" }}
|
||||
initial={{ opacity: 0, scale: 0.9 }}
|
||||
animate={{ opacity: 1, scale: 1 }}
|
||||
transition={{ delay: 0.3 }}
|
||||
whileHover={{ scale: 1.03 }}
|
||||
whileTap={{ scale: 0.97 }}
|
||||
onClick={() => setShowModal(true)}
|
||||
>
|
||||
<span className="text-2xl leading-none">{getWeatherEmoji(weather.weatherCode)}</span>
|
||||
<div>
|
||||
<div className="text-xl font-black leading-tight" style={{ color: "var(--text-primary)" }}>{weather.temp}°C</div>
|
||||
<div className="text-xs leading-tight" style={{ color: "var(--text-secondary)" }}>{weather.desc}</div>
|
||||
</div>
|
||||
<span className="text-xs ml-1" style={{ color: "var(--text-secondary)", opacity: 0.6 }}>▼</span>
|
||||
</motion.button>
|
||||
) : (
|
||||
<div className="text-sm px-4 py-2 rounded-2xl" style={{ color: "var(--text-secondary)", background: "rgba(255,255,255,0.04)" }}>
|
||||
🌤️ {weather ? "Загрузка..." : "—"}
|
||||
</div>
|
||||
)}
|
||||
|
||||
{/* Theme toggle + Demo badge */}
|
||||
<div className="flex items-center gap-3">
|
||||
{isDemo && (
|
||||
<motion.span
|
||||
className="text-xs px-2.5 py-1 rounded-full font-semibold"
|
||||
style={{ background: "rgba(245,158,11,0.15)", color: "#f59e0b", border: "1px solid rgba(245,158,11,0.3)" }}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
>
|
||||
Demo
|
||||
</motion.span>
|
||||
)}
|
||||
<ThemeToggle isDark={isDark} onToggle={onToggleTheme} />
|
||||
</div>
|
||||
</motion.div>
|
||||
|
||||
{/* Weather Modal */}
|
||||
<AnimatePresence>
|
||||
{showModal && weather && (
|
||||
<motion.div
|
||||
className="fixed inset-0 z-50 flex items-center justify-center p-6"
|
||||
style={{ background: "rgba(0,0,0,0.7)", backdropFilter: "blur(12px)" }}
|
||||
initial={{ opacity: 0 }}
|
||||
animate={{ opacity: 1 }}
|
||||
exit={{ opacity: 0 }}
|
||||
onClick={() => setShowModal(false)}
|
||||
>
|
||||
Demo
|
||||
</motion.span>
|
||||
<motion.div
|
||||
className="glass-card p-8 w-full max-w-lg"
|
||||
style={{ borderRadius: "28px", background: "rgba(15,15,25,0.9)", border: "1px solid rgba(255,255,255,0.12)" }}
|
||||
initial={{ scale: 0.9, y: 20 }}
|
||||
animate={{ scale: 1, y: 0 }}
|
||||
exit={{ scale: 0.9, y: 20 }}
|
||||
onClick={e => e.stopPropagation()}
|
||||
>
|
||||
{/* Header */}
|
||||
<div className="flex items-center justify-between mb-6">
|
||||
<h2 className="text-xl font-bold" style={{ color: "var(--text-primary)" }}>🌍 Санкт-Петербург</h2>
|
||||
<button
|
||||
onClick={() => setShowModal(false)}
|
||||
className="w-9 h-9 rounded-full flex items-center justify-center text-lg"
|
||||
style={{ background: "rgba(255,255,255,0.08)", color: "var(--text-secondary)" }}
|
||||
>✕</button>
|
||||
</div>
|
||||
|
||||
{/* Current */}
|
||||
<div className="flex items-center gap-5 mb-8">
|
||||
<span style={{ fontSize: "72px", lineHeight: 1 }}>{getWeatherEmoji(weather.weatherCode)}</span>
|
||||
<div>
|
||||
<div className="font-black" style={{ fontSize: "64px", lineHeight: 1, color: "var(--text-primary)" }}>
|
||||
{weather.temp}°
|
||||
</div>
|
||||
<div className="text-lg" style={{ color: "var(--text-secondary)" }}>{weather.desc}</div>
|
||||
<div className="flex gap-4 mt-2 text-sm" style={{ color: "var(--text-secondary)" }}>
|
||||
{weather.feelsLike && weather.feelsLike !== "—" && <span>Ощущается {weather.feelsLike}°</span>}
|
||||
{weather.humidity && weather.humidity !== "—" && <span>💧 {weather.humidity}%</span>}
|
||||
{weather.windSpeed && weather.windSpeed !== "—" && <span>💨 {weather.windSpeed} км/ч</span>}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
{/* Forecast */}
|
||||
{weather.forecast && weather.forecast.length > 0 && (
|
||||
<div>
|
||||
<div className="text-xs font-semibold uppercase tracking-widest mb-3" style={{ color: "var(--text-secondary)" }}>
|
||||
Прогноз
|
||||
</div>
|
||||
<div className="grid gap-2">
|
||||
{weather.forecast.map((day: any, i: number) => (
|
||||
<div key={i} className="flex items-center justify-between px-4 py-3 rounded-2xl"
|
||||
style={{ background: "rgba(255,255,255,0.04)", border: "1px solid rgba(255,255,255,0.06)" }}>
|
||||
<span className="text-sm font-semibold w-16" style={{ color: "var(--text-primary)" }}>
|
||||
{getDayName(day.date)}
|
||||
</span>
|
||||
<span className="text-2xl">{getWeatherEmoji(day.weatherCode)}</span>
|
||||
<span className="text-sm" style={{ color: "var(--text-secondary)" }}>{day.desc}</span>
|
||||
<span className="text-sm font-semibold" style={{ color: "var(--text-primary)" }}>
|
||||
{day.maxTemp}° / <span style={{ color: "var(--text-secondary)" }}>{day.minTemp}°</span>
|
||||
</span>
|
||||
</div>
|
||||
))}
|
||||
</div>
|
||||
</div>
|
||||
)}
|
||||
</motion.div>
|
||||
</motion.div>
|
||||
)}
|
||||
<ThemeToggle isDark={isDark} onToggle={onToggleTheme} />
|
||||
</div>
|
||||
</motion.div>
|
||||
</AnimatePresence>
|
||||
</>
|
||||
);
|
||||
}
|
||||
|
||||
@@ -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