Files
smart-home-tablet/components/TopBar.tsx
Cosmo 088cd35ea6
All checks were successful
Deploy to Coolify / deploy (push) Successful in 5s
feat: new layout, rooms row, fix weather+HA, fix BottomNav overflow
- Remove TasksCard and SavingsCard from home tab
- New grid layout: lights+thermostat row 1, purifier+weather row 2
- Add RoomsRow component with room navigation
- Fix HA entity mapping: fan.zhimi_rmb1_9528_air_purifier → fan.air_purifier
- Add real entity aliases for HA route
- Fix weather route: add timeout, better error handling
- Fix BottomNav: use 100dvh + flex-shrink-0
- TopBar: accept isDemo prop, show Demo badge in header
- WeatherCard: compact prop, better loading/error states
- globals.css: add no-scrollbar utility
2026-04-22 10:33:20 +00:00

135 lines
3.8 KiB
TypeScript
Raw Blame History

This file contains invisible Unicode characters
This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
"use client";
import { useState, useEffect } from "react";
import { motion } from "framer-motion";
import ThemeToggle from "./ThemeToggle";
function getWeatherEmoji(code: string): string {
const c = parseInt(code);
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 >= 200 && c <= 210) return "⛈️";
if (c >= 210 && c <= 260) return "❄️";
if (c >= 260 && c <= 300) return "🌨️";
if (c >= 300 && c <= 400) return "🌧️";
return "🌤️";
}
interface Props {
isDark: boolean;
onToggleTheme: () => void;
weather: any;
isDemo?: boolean;
}
export default function TopBar({ isDark, onToggleTheme, weather, isDemo }: Props) {
const [time, setTime] = useState("");
const [date, setDate] = useState("");
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",
})
);
};
update();
const id = setInterval(update, 1000);
return () => clearInterval(id);
}, []);
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)}
</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)",
}}
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
>
Demo
</motion.span>
)}
<ThemeToggle isDark={isDark} onToggle={onToggleTheme} />
</div>
</motion.div>
);
}