import { useState } from "react";
import { KIDS, DAYS, STATUSES, SUBJECTS, SOURCES, SUBJECT_ICONS } from "./data/constants";
import { useTasks } from "./hooks/useTasks";
import "./App.css";
function getWeekDates() {
const today = new Date();
const monday = new Date(today);
monday.setDate(today.getDate() - ((today.getDay() + 6) % 7));
return Array.from({ length: 5 }, (_, i) => {
const d = new Date(monday);
d.setDate(monday.getDate() + i);
return d;
});
}
const EMPTY_FORM = { subject: "", title: "", status: "new", due: "", source: "Notebook", type: "homework" };
export default function App() {
const [activeKid, setActiveKid] = useState("abdulla");
const [activeDay, setActiveDay] = useState(() => {
const d = new Date().getDay();
return d >= 1 && d <= 5 ? d - 1 : 0;
});
const [activeTab, setActiveTab] = useState("homework");
const [showForm, setShowForm] = useState(false);
const [form, setForm] = useState(EMPTY_FORM);
const { tasks, addTask, updateStatus, removeTask } = useTasks();
const weekDates = getWeekDates();
const today = new Date();
const kid = KIDS.find((k) => k.id === activeKid);
const kidTasks = tasks[activeKid] || [];
const filtered = kidTasks.filter((t) => t.type === activeTab);
const dayTasks = kidTasks.filter(
(t) => new Date(t.due).toDateString() === weekDates[activeDay]?.toDateString()
);
const stats = {
new: kidTasks.filter((t) => t.status === "new").length,
inprogress: kidTasks.filter((t) => t.status === "inprogress").length,
completed: kidTasks.filter((t) => t.status === "completed").length,
};
function handleAddTask() {
if (!form.title || !form.subject || !form.due) return;
addTask(activeKid, form);
setForm(EMPTY_FORM);
setShowForm(false);
setActiveTab(form.type);
}
return (
{/* Header */}
ASCS
American School of Creativity Science
Homework Tracker 📚
{today.toLocaleDateString("en-US", { weekday: "long", year: "numeric", month: "long", day: "numeric" })}
{/* Kid Switcher */}
{KIDS.map((k) => (
))}
{/* Weekly Calendar */}
📅 This Week
{weekDates.map((d, i) => {
const isToday = d.toDateString() === today.toDateString();
const hasTasks = kidTasks.filter((t) => new Date(t.due).toDateString() === d.toDateString()).length;
return (
);
})}
{dayTasks.length > 0 && (
Due {weekDates[activeDay]?.toLocaleDateString("en-US", { weekday: "short", month: "short", day: "numeric" })}:{" "}
{dayTasks.map((t) => t.title).join(" • ")}
)}
{/* Stats */}
{STATUSES.map((s) => (
{stats[s.id]}
{s.label}
))}
{/* Tabs + Add button */}
{["homework", "project"].map((tab) => (
))}
{/* Add Form */}
{showForm && (
)}
{/* Task List */}
{filtered.length === 0 && (
{activeTab === "homework" ? "🎉" : "🌟"}
No {activeTab}s yet!
Tap + Add to add one
)}
{filtered.map((task) => {
const st = STATUSES.find((s) => s.id === task.status);
const dueDate = new Date(task.due);
const isOverdue = dueDate < today && task.status !== "completed";
return (
{SUBJECT_ICONS[task.subject] || "📚"}
{task.title}
{task.subject}
{st.label}
{isOverdue ? "⚠️ " : "📅 "}
{dueDate.toLocaleDateString("en-US", { month: "short", day: "numeric" })}
via {task.source}
);
})}
);
}