// Calendar view: month grid with task pills colored by project. const CALIcons = window.Icons; const { toDateKey: calDateKey } = window.PMStore; const DAY_NAMES = ['Pzt','Sal','Çar','Per','Cum','Cmt','Paz']; const MONTH_NAMES = ['Ocak','Şubat','Mart','Nisan','Mayıs','Haziran','Temmuz','Ağustos','Eylül','Ekim','Kasım','Aralık']; function CalendarView({ state, onSelectTask, query }) { const [cursor, setCursor] = React.useState(() => { const d = new Date(); d.setDate(1); return d; }); const projById = Object.fromEntries(state.projects.map(p => [p.id, p])); const tagById = Object.fromEntries(state.tags.map(t => [t.id, t])); const tasks = state.tasks.filter(t => { if (!t.due) return false; if (!query) return true; const q = query.toLowerCase(); return t.title.toLowerCase().includes(q) || t.tags.some(tid => (tagById[tid]?.name || '').toLowerCase().includes(q)); }); const year = cursor.getFullYear(); const month = cursor.getMonth(); const firstDay = new Date(year, month, 1); const lastDay = new Date(year, month + 1, 0); // Monday-start grid let startWeekday = firstDay.getDay(); // 0=Sun startWeekday = (startWeekday + 6) % 7; // 0=Mon const daysInMonth = lastDay.getDate(); const totalCells = Math.ceil((startWeekday + daysInMonth) / 7) * 7; const today = new Date(); today.setHours(0,0,0,0); const cells = []; for (let i = 0; i < totalCells; i++) { const dayOffset = i - startWeekday; const date = new Date(year, month, 1 + dayOffset); const inMonth = date.getMonth() === month; const isoStr = calDateKey(date); const dayTasks = tasks.filter(t => t.due === isoStr); cells.push({ date, inMonth, isToday: date.getTime() === today.getTime(), tasks: dayTasks }); } const goToToday = () => { const d = new Date(); d.setDate(1); setCursor(d); }; return (
{MONTH_NAMES[month]} {year}
Proje renkleri: {state.projects.map(p => ( {p.name} ))}
{DAY_NAMES.map(n =>
{n}
)} {cells.map((c, i) => (
{c.date.getDate()}
{c.tasks.slice(0, 4).map(t => { const proj = projById[t.projectId]; return (
onSelectTask(t.id)} title={t.title} > {t.title}
); })} {c.tasks.length > 4 && (
+{c.tasks.length - 4} daha
)}
))}
); } window.CalendarView = CalendarView;