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_URL = process.env.HA_URL || "http://192.168.31.110:8123";
|
||||||
const HA_TOKEN = process.env.HA_TOKEN || "";
|
const HA_TOKEN = process.env.HA_TOKEN || "";
|
||||||
|
|
||||||
// Real entity IDs → normalized keys used in the dashboard
|
|
||||||
const REAL_ENTITY_ALIASES: Record<string, string> = {
|
const REAL_ENTITY_ALIASES: Record<string, string> = {
|
||||||
"fan.zhimi_rmb1_9528_air_purifier": "fan.air_purifier",
|
"fan.zhimi_rmb1_9528_air_purifier": "fan.air_purifier",
|
||||||
};
|
};
|
||||||
|
|
||||||
// Mock data for entities that don't exist yet (квартира строится)
|
|
||||||
const MOCK_MISSING: Record<string, any> = {
|
const MOCK_MISSING: Record<string, any> = {
|
||||||
"light.living_room": {
|
"light.living_room": {
|
||||||
entity_id: "light.living_room",
|
entity_id: "light.living_room",
|
||||||
state: "off",
|
state: "off",
|
||||||
attributes: { brightness: 0, friendly_name: "Свет Гостиная" },
|
attributes: { brightness: 0, friendly_name: "Свет Гостиная" },
|
||||||
|
_mock: true,
|
||||||
},
|
},
|
||||||
"light.bedroom": {
|
"light.bedroom": {
|
||||||
entity_id: "light.bedroom",
|
entity_id: "light.bedroom",
|
||||||
state: "off",
|
state: "off",
|
||||||
attributes: { friendly_name: "Свет Спальня" },
|
attributes: { friendly_name: "Свет Спальня" },
|
||||||
|
_mock: true,
|
||||||
},
|
},
|
||||||
"climate.thermostat": {
|
"climate.thermostat": {
|
||||||
entity_id: "climate.thermostat",
|
entity_id: "climate.thermostat",
|
||||||
@@ -29,15 +29,17 @@ const MOCK_MISSING: Record<string, any> = {
|
|||||||
temperature: 22,
|
temperature: 22,
|
||||||
friendly_name: "Термостат",
|
friendly_name: "Термостат",
|
||||||
},
|
},
|
||||||
|
_mock: true,
|
||||||
},
|
},
|
||||||
"fan.air_purifier": {
|
"fan.air_purifier": {
|
||||||
entity_id: "fan.air_purifier",
|
entity_id: "fan.air_purifier",
|
||||||
state: "on",
|
state: "off",
|
||||||
attributes: {
|
attributes: {
|
||||||
preset_mode: "Auto",
|
preset_mode: "Auto",
|
||||||
friendly_name: "Очиститель воздуха",
|
friendly_name: "Очиститель воздуха",
|
||||||
preset_modes: ["Auto", "Night", "High"],
|
preset_modes: ["Auto", "Night", "High"],
|
||||||
},
|
},
|
||||||
|
_mock: true,
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
@@ -59,20 +61,23 @@ export async function GET(req: NextRequest) {
|
|||||||
Authorization: `Bearer ${HA_TOKEN}`,
|
Authorization: `Bearer ${HA_TOKEN}`,
|
||||||
"Content-Type": "application/json",
|
"Content-Type": "application/json",
|
||||||
},
|
},
|
||||||
next: { revalidate: 0 },
|
cache: "no-store",
|
||||||
});
|
});
|
||||||
|
|
||||||
if (!res.ok) throw new Error(`HA responded ${res.status}`);
|
if (!res.ok) throw new Error(`HA responded ${res.status}`);
|
||||||
const states: any[] = await res.json();
|
const states: any[] = await res.json();
|
||||||
|
|
||||||
// Build filtered map with normalized keys
|
|
||||||
const filtered: Record<string, any> = {};
|
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) {
|
for (const s of states) {
|
||||||
// Direct match
|
|
||||||
if (RELEVANT_KEYS.includes(s.entity_id)) {
|
if (RELEVANT_KEYS.includes(s.entity_id)) {
|
||||||
filtered[s.entity_id] = s;
|
filtered[s.entity_id] = s;
|
||||||
}
|
}
|
||||||
// Alias match (real entity → normalized key)
|
|
||||||
if (REAL_ENTITY_ALIASES[s.entity_id]) {
|
if (REAL_ENTITY_ALIASES[s.entity_id]) {
|
||||||
const normalizedKey = REAL_ENTITY_ALIASES[s.entity_id];
|
const normalizedKey = REAL_ENTITY_ALIASES[s.entity_id];
|
||||||
filtered[normalizedKey] = {
|
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) {
|
for (const key of RELEVANT_KEYS) {
|
||||||
if (!filtered[key]) {
|
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);
|
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) {
|
} catch (e) {
|
||||||
// Fallback to full mock
|
|
||||||
return NextResponse.json({ demo: true, states: MOCK_MISSING });
|
return NextResponse.json({ demo: true, states: MOCK_MISSING });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
export async function POST(req: NextRequest) {
|
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) {
|
if (!HA_TOKEN) {
|
||||||
return NextResponse.json({ success: true, demo: true });
|
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(
|
const realEntityId = Object.keys(REAL_ENTITY_ALIASES).find(
|
||||||
k => REAL_ENTITY_ALIASES[k] === entity_id
|
k => REAL_ENTITY_ALIASES[k] === entity_id
|
||||||
) || entity_id;
|
) || entity_id;
|
||||||
@@ -122,9 +144,12 @@ export async function POST(req: NextRequest) {
|
|||||||
body: JSON.stringify({ entity_id: realEntityId, ...serviceData }),
|
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 });
|
return NextResponse.json({ success: true });
|
||||||
} catch (e) {
|
} 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 {
|
.no-scrollbar::-webkit-scrollbar {
|
||||||
display: none;
|
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 LightCard from "@/components/cards/LightCard";
|
||||||
import TemperatureCard from "@/components/cards/TemperatureCard";
|
import TemperatureCard from "@/components/cards/TemperatureCard";
|
||||||
import AirPurifierCard from "@/components/cards/AirPurifierCard";
|
import AirPurifierCard from "@/components/cards/AirPurifierCard";
|
||||||
import TasksCard from "@/components/cards/TasksCard";
|
|
||||||
import WeatherCard from "@/components/cards/WeatherCard";
|
import WeatherCard from "@/components/cards/WeatherCard";
|
||||||
import RoomsRow from "@/components/RoomsRow";
|
import RoomsRow from "@/components/RoomsRow";
|
||||||
import { useHA, useWeather, useTasks } from "@/hooks/useHA";
|
import { useHA, useWeather } from "@/hooks/useHA";
|
||||||
|
|
||||||
// Stagger container variants
|
// Stagger container variants
|
||||||
const containerVariants = {
|
const containerVariants = {
|
||||||
@@ -30,7 +30,6 @@ export default function Home() {
|
|||||||
|
|
||||||
const { data: haData, loading: haLoading, refresh: refreshHA } = useHA(15000);
|
const { data: haData, loading: haLoading, refresh: refreshHA } = useHA(15000);
|
||||||
const weather = useWeather();
|
const weather = useWeather();
|
||||||
const { tasks, refresh: refreshTasks } = useTasks();
|
|
||||||
|
|
||||||
// Apply theme to html element
|
// Apply theme to html element
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
@@ -299,20 +298,6 @@ export default function Home() {
|
|||||||
</motion.div>
|
</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 ═══════════════ */}
|
{/* ═══════════════ SETTINGS TAB ═══════════════ */}
|
||||||
{activeTab === "settings" && (
|
{activeTab === "settings" && (
|
||||||
<motion.div
|
<motion.div
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { motion } from "framer-motion";
|
import { motion } from "framer-motion";
|
||||||
import { Home, Cpu, CheckSquare, Settings } from "lucide-react";
|
import { Home, Cpu, Settings } from "lucide-react";
|
||||||
|
|
||||||
interface Props {
|
interface Props {
|
||||||
active: string;
|
active: string;
|
||||||
@@ -11,14 +11,13 @@ interface Props {
|
|||||||
const TABS = [
|
const TABS = [
|
||||||
{ id: "home", label: "Главная", icon: Home, color: "#6366f1" },
|
{ id: "home", label: "Главная", icon: Home, color: "#6366f1" },
|
||||||
{ id: "devices", label: "Устройства", icon: Cpu, color: "#3b82f6" },
|
{ id: "devices", label: "Устройства", icon: Cpu, color: "#3b82f6" },
|
||||||
{ id: "tasks", label: "Задачи", icon: CheckSquare, color: "#8b5cf6" },
|
|
||||||
{ id: "settings", label: "Настройки", icon: Settings, color: "#10b981" },
|
{ id: "settings", label: "Настройки", icon: Settings, color: "#10b981" },
|
||||||
];
|
];
|
||||||
|
|
||||||
export default function BottomNav({ active, onChange }: Props) {
|
export default function BottomNav({ active, onChange }: Props) {
|
||||||
return (
|
return (
|
||||||
<motion.div
|
<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" }}
|
style={{ borderRadius: "20px" }}
|
||||||
initial={{ opacity: 0, y: 20 }}
|
initial={{ opacity: 0, y: 20 }}
|
||||||
animate={{ opacity: 1, y: 0 }}
|
animate={{ opacity: 1, y: 0 }}
|
||||||
@@ -31,7 +30,7 @@ export default function BottomNav({ active, onChange }: Props) {
|
|||||||
<motion.button
|
<motion.button
|
||||||
key={tab.id}
|
key={tab.id}
|
||||||
onClick={() => onChange(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 }}
|
whileTap={{ scale: 0.85 }}
|
||||||
>
|
>
|
||||||
{isActive && (
|
{isActive && (
|
||||||
@@ -46,15 +45,8 @@ export default function BottomNav({ active, onChange }: Props) {
|
|||||||
transition={{ type: "spring", stiffness: 450, damping: 30 }}
|
transition={{ type: "spring", stiffness: 450, damping: 30 }}
|
||||||
/>
|
/>
|
||||||
)}
|
)}
|
||||||
<Icon
|
<Icon size={22} color={isActive ? tab.color : "var(--text-secondary)"} strokeWidth={isActive ? 2 : 1.5} />
|
||||||
size={22}
|
<span className="text-xs font-semibold" style={{ color: isActive ? tab.color : "var(--text-secondary)" }}>
|
||||||
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}
|
{tab.label}
|
||||||
</span>
|
</span>
|
||||||
</motion.button>
|
</motion.button>
|
||||||
|
|||||||
@@ -1,7 +1,7 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect } from "react";
|
import { useState, useEffect } from "react";
|
||||||
import { motion } from "framer-motion";
|
import { motion, AnimatePresence } from "framer-motion";
|
||||||
import ThemeToggle from "./ThemeToggle";
|
import ThemeToggle from "./ThemeToggle";
|
||||||
|
|
||||||
function getWeatherEmoji(code: string): string {
|
function getWeatherEmoji(code: string): string {
|
||||||
@@ -9,15 +9,22 @@ function getWeatherEmoji(code: string): string {
|
|||||||
if (c === 113) return "☀️";
|
if (c === 113) return "☀️";
|
||||||
if (c === 116) return "⛅";
|
if (c === 116) return "⛅";
|
||||||
if (c === 119 || c === 122) return "☁️";
|
if (c === 119 || c === 122) return "☁️";
|
||||||
if (c >= 176 && c <= 182) return "🌦️";
|
if (c >= 176 && c <= 300) return "🌧️";
|
||||||
if (c >= 185 && c <= 200) return "🌧️";
|
|
||||||
if (c >= 200 && c <= 210) return "⛈️";
|
if (c >= 200 && c <= 210) return "⛈️";
|
||||||
if (c >= 210 && c <= 260) return "❄️";
|
if (c >= 210 && c <= 260) return "❄️";
|
||||||
if (c >= 260 && c <= 300) return "🌨️";
|
|
||||||
if (c >= 300 && c <= 400) return "🌧️";
|
|
||||||
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 {
|
interface Props {
|
||||||
isDark: boolean;
|
isDark: boolean;
|
||||||
onToggleTheme: () => void;
|
onToggleTheme: () => void;
|
||||||
@@ -28,27 +35,23 @@ interface Props {
|
|||||||
export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props) {
|
export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props) {
|
||||||
const [time, setTime] = useState("");
|
const [time, setTime] = useState("");
|
||||||
const [date, setDate] = useState("");
|
const [date, setDate] = useState("");
|
||||||
|
const [showModal, setShowModal] = useState(false);
|
||||||
|
|
||||||
useEffect(() => {
|
useEffect(() => {
|
||||||
const update = () => {
|
const update = () => {
|
||||||
const now = new Date();
|
const now = new Date();
|
||||||
setTime(
|
setTime(now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" }));
|
||||||
now.toLocaleTimeString("ru-RU", { hour: "2-digit", minute: "2-digit" })
|
setDate(now.toLocaleDateString("ru-RU", { weekday: "short", day: "numeric", month: "long" }));
|
||||||
);
|
|
||||||
setDate(
|
|
||||||
now.toLocaleDateString("ru-RU", {
|
|
||||||
weekday: "short",
|
|
||||||
day: "numeric",
|
|
||||||
month: "long",
|
|
||||||
})
|
|
||||||
);
|
|
||||||
};
|
};
|
||||||
update();
|
update();
|
||||||
const id = setInterval(update, 1000);
|
const id = setInterval(update, 1000);
|
||||||
return () => clearInterval(id);
|
return () => clearInterval(id);
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
|
const hasWeather = weather && weather.temp && weather.temp !== "—";
|
||||||
|
|
||||||
return (
|
return (
|
||||||
|
<>
|
||||||
<motion.div
|
<motion.div
|
||||||
className="glass-card px-6 py-3 flex items-center justify-between no-select flex-shrink-0"
|
className="glass-card px-6 py-3 flex items-center justify-between no-select flex-shrink-0"
|
||||||
style={{ borderRadius: "20px" }}
|
style={{ borderRadius: "20px" }}
|
||||||
@@ -58,69 +61,45 @@ export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props
|
|||||||
>
|
>
|
||||||
{/* Time & Date */}
|
{/* Time & Date */}
|
||||||
<div className="flex items-baseline gap-4">
|
<div className="flex items-baseline gap-4">
|
||||||
<span
|
<span className="font-black tracking-tight leading-none" style={{ fontSize: "42px", color: "var(--text-primary)" }}>
|
||||||
className="font-black tracking-tight leading-none"
|
|
||||||
style={{ fontSize: "42px", color: "var(--text-primary)" }}
|
|
||||||
>
|
|
||||||
{time}
|
{time}
|
||||||
</span>
|
</span>
|
||||||
<span
|
<span className="text-sm font-medium capitalize" style={{ color: "var(--text-secondary)" }}>
|
||||||
className="text-sm font-medium capitalize"
|
|
||||||
style={{ color: "var(--text-secondary)" }}
|
|
||||||
>
|
|
||||||
{date}
|
{date}
|
||||||
</span>
|
</span>
|
||||||
</div>
|
</div>
|
||||||
|
|
||||||
{/* Weather pill */}
|
{/* Weather pill — clickable */}
|
||||||
{weather && weather.temp !== "—" ? (
|
{hasWeather ? (
|
||||||
<motion.div
|
<motion.button
|
||||||
className="flex items-center gap-3 px-5 py-2 rounded-2xl"
|
className="flex items-center gap-3 px-5 py-2 rounded-2xl cursor-pointer"
|
||||||
style={{
|
style={{ background: "rgba(59,130,246,0.1)", border: "1px solid rgba(59,130,246,0.22)" }}
|
||||||
background: "rgba(59,130,246,0.1)",
|
|
||||||
border: "1px solid rgba(59,130,246,0.22)",
|
|
||||||
}}
|
|
||||||
initial={{ opacity: 0, scale: 0.9 }}
|
initial={{ opacity: 0, scale: 0.9 }}
|
||||||
animate={{ opacity: 1, scale: 1 }}
|
animate={{ opacity: 1, scale: 1 }}
|
||||||
transition={{ delay: 0.3 }}
|
transition={{ delay: 0.3 }}
|
||||||
|
whileHover={{ scale: 1.03 }}
|
||||||
|
whileTap={{ scale: 0.97 }}
|
||||||
|
onClick={() => setShowModal(true)}
|
||||||
>
|
>
|
||||||
<span className="text-2xl leading-none">
|
<span className="text-2xl leading-none">{getWeatherEmoji(weather.weatherCode)}</span>
|
||||||
{getWeatherEmoji(weather.weatherCode)}
|
|
||||||
</span>
|
|
||||||
<div>
|
<div>
|
||||||
<div
|
<div className="text-xl font-black leading-tight" style={{ color: "var(--text-primary)" }}>{weather.temp}°C</div>
|
||||||
className="text-xl font-black leading-tight"
|
<div className="text-xs leading-tight" style={{ color: "var(--text-secondary)" }}>{weather.desc}</div>
|
||||||
style={{ color: "var(--text-primary)" }}
|
|
||||||
>
|
|
||||||
{weather.temp}°C
|
|
||||||
</div>
|
</div>
|
||||||
<div
|
<span className="text-xs ml-1" style={{ color: "var(--text-secondary)", opacity: 0.6 }}>▼</span>
|
||||||
className="text-xs leading-tight"
|
</motion.button>
|
||||||
style={{ color: "var(--text-secondary)" }}
|
) : (
|
||||||
>
|
<div className="text-sm px-4 py-2 rounded-2xl" style={{ color: "var(--text-secondary)", background: "rgba(255,255,255,0.04)" }}>
|
||||||
{weather.desc}
|
🌤️ {weather ? "Загрузка..." : "—"}
|
||||||
</div>
|
</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 */}
|
{/* Theme toggle + Demo badge */}
|
||||||
<div className="flex items-center gap-3">
|
<div className="flex items-center gap-3">
|
||||||
{isDemo && (
|
{isDemo && (
|
||||||
<motion.span
|
<motion.span
|
||||||
className="text-xs px-2.5 py-1 rounded-full font-semibold"
|
className="text-xs px-2.5 py-1 rounded-full font-semibold"
|
||||||
style={{
|
style={{ background: "rgba(245,158,11,0.15)", color: "#f59e0b", border: "1px solid rgba(245,158,11,0.3)" }}
|
||||||
background: "rgba(245,158,11,0.15)",
|
|
||||||
color: "#f59e0b",
|
|
||||||
border: "1px solid rgba(245,158,11,0.3)",
|
|
||||||
}}
|
|
||||||
initial={{ opacity: 0 }}
|
initial={{ opacity: 0 }}
|
||||||
animate={{ opacity: 1 }}
|
animate={{ opacity: 1 }}
|
||||||
>
|
>
|
||||||
@@ -130,5 +109,79 @@ export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props
|
|||||||
<ThemeToggle isDark={isDark} onToggle={onToggleTheme} />
|
<ThemeToggle isDark={isDark} onToggle={onToggleTheme} />
|
||||||
</div>
|
</div>
|
||||||
</motion.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)}
|
||||||
|
>
|
||||||
|
<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>
|
||||||
|
)}
|
||||||
|
</AnimatePresence>
|
||||||
|
</>
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -1,10 +1,9 @@
|
|||||||
"use client";
|
"use client";
|
||||||
|
|
||||||
import { useState, useEffect, useCallback } from "react";
|
import { useState, useEffect, useCallback } from "react";
|
||||||
import { HAStates } from "@/lib/ha";
|
|
||||||
|
|
||||||
export function useHA(refreshInterval = 10000) {
|
export function useHA(refreshInterval = 10000) {
|
||||||
const [data, setData] = useState<HAStates | null>(null);
|
const [data, setData] = useState<any>(null);
|
||||||
const [loading, setLoading] = useState(true);
|
const [loading, setLoading] = useState(true);
|
||||||
|
|
||||||
const refresh = useCallback(async () => {
|
const refresh = useCallback(async () => {
|
||||||
@@ -31,26 +30,34 @@ export function useHA(refreshInterval = 10000) {
|
|||||||
export function useWeather() {
|
export function useWeather() {
|
||||||
const [weather, setWeather] = useState<any>(null);
|
const [weather, setWeather] = useState<any>(null);
|
||||||
|
|
||||||
useEffect(() => {
|
const fetchWeather = useCallback(async () => {
|
||||||
fetch("/api/weather")
|
try {
|
||||||
.then((r) => r.json())
|
const res = await fetch("/api/weather", { cache: "no-store" });
|
||||||
.then(setWeather)
|
const json = await res.json();
|
||||||
.catch(() => {});
|
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;
|
return weather;
|
||||||
}
|
}
|
||||||
|
|
||||||
export function useTasks() {
|
export function useTasks() {
|
||||||
const [tasks, setTasks] = useState<any[]>([]);
|
const [tasks, setTasks] = useState<any[]>([]);
|
||||||
const [demo, setDemo] = useState(false);
|
|
||||||
|
|
||||||
const refresh = useCallback(async () => {
|
const refresh = useCallback(async () => {
|
||||||
try {
|
try {
|
||||||
const res = await fetch("/api/tasks", { cache: "no-store" });
|
const res = await fetch("/api/tasks", { cache: "no-store" });
|
||||||
const json = await res.json();
|
const json = await res.json();
|
||||||
setTasks(json.tasks || []);
|
setTasks(json.tasks || []);
|
||||||
setDemo(!!json.demo);
|
|
||||||
} catch (e) {}
|
} catch (e) {}
|
||||||
}, []);
|
}, []);
|
||||||
|
|
||||||
@@ -58,22 +65,5 @@ export function useTasks() {
|
|||||||
refresh();
|
refresh();
|
||||||
}, [refresh]);
|
}, [refresh]);
|
||||||
|
|
||||||
return { tasks, setTasks, demo, refresh };
|
return { tasks, setTasks, 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 };
|
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user