Initial commit: Digital Home dashboard

This commit is contained in:
Cosmo
2026-04-15 20:31:28 +00:00
commit c5c4603903
33 changed files with 1384 additions and 0 deletions

View File

@@ -0,0 +1,77 @@
"use client";
import { CheckSquare, RefreshCw, Circle, CheckCircle2 } from "lucide-react";
import { useEffect, useState } from "react";
interface Task {
id: number;
title: string;
done?: boolean;
priority?: string;
}
export function TasksWidget() {
const [tasks, setTasks] = useState<Task[]>([]);
const [loading, setLoading] = useState(true);
const fetchTasks = async () => {
setLoading(true);
try {
const res = await fetch("/api/tasks");
const data = await res.json();
const list = data.tasks ?? data ?? [];
setTasks(Array.isArray(list) ? list : []);
} catch {
setTasks([]);
} finally {
setLoading(false);
}
};
useEffect(() => { fetchTasks(); }, []);
const priorityColor: Record<string, string> = {
high: "text-red-400",
medium: "text-yellow-400",
low: "text-green-400",
};
return (
<div className="glass-card p-5">
<div className="flex items-center justify-between mb-4">
<div className="flex items-center gap-2">
<CheckSquare className="w-4 h-4 text-emerald-400" />
<span className="text-sm font-medium text-slate-300">Задачи сегодня</span>
</div>
<button onClick={fetchTasks} className="text-slate-500 hover:text-slate-300 transition-colors">
<RefreshCw className="w-3.5 h-3.5" />
</button>
</div>
{loading ? (
<div className="space-y-2 animate-pulse">
{[1,2,3].map(i => <div key={i} className="h-8 bg-slate-700/50 rounded" />)}
</div>
) : tasks.length === 0 ? (
<div className="flex flex-col items-center justify-center py-4 text-slate-500">
<CheckSquare className="w-8 h-8 mb-2 opacity-30" />
<span className="text-sm">Задач нет</span>
</div>
) : (
<div className="space-y-1.5 max-h-36 overflow-y-auto">
{tasks.map((task) => (
<div key={task.id} className="flex items-start gap-2 p-2 rounded-lg hover:bg-slate-800/40 transition-colors">
{task.done ? (
<CheckCircle2 className="w-4 h-4 text-emerald-400 shrink-0 mt-0.5" />
) : (
<Circle className="w-4 h-4 text-slate-500 shrink-0 mt-0.5" />
)}
<span className={"text-sm " + (task.done ? "text-slate-500 line-through" : "text-slate-200")}>
{task.title}
</span>
</div>
))}
</div>
)}
</div>
);
}