import "./monthGrid.css"; import { ViewController } from "../viewController"; import * as React from "../../react"; import TaskViewModel from "../../ViewModel/Pages/taskViewModel"; import CoreViewModel from "../../ViewModel/Global/coreViewModel"; import { localeCompare } from "../../Model/Utility/utility"; import { MonthGrid } from "../../Model/Files/calendarModel"; export function MonthGrid( coreViewModel: CoreViewModel, monthGrid: MonthGrid>, selectedDate: React.State, handleDrop: (date: string) => void, ) { const dayLabels: HTMLElement[] = []; let currentWeekday = monthGrid.firstDayOfWeek; while (dayLabels.length < 7) { dayLabels.push( { coreViewModel.translations.regional.weekdays.abbreviated[ currentWeekday ] } , ); currentWeekday++; if (currentWeekday == 7) currentWeekday = 0; } const offsetElements: HTMLElement[] = []; for (let i = 0; i < monthGrid.offset; i++) { offsetElements.push(
); } const converter: React.StateItemConverter = ( taskViewModel, ) => { const view = ( {taskViewModel.task.name} ); taskViewModel.index.subscribe((newIndex) => { view.style.order = newIndex; }); return view; }; return (
{...dayLabels}
{...offsetElements} {...Object.entries(monthGrid.days) .sort((a, b) => localeCompare(a[0], b[0])) .map((entry) => { const [date, mapState] = entry; const isSelected = React.createProxyState( [selectedDate], () => selectedDate.value == parseInt(date), ); const isToday = React.createProxyState( [coreViewModel.todayDate], () => { return ( monthGrid.isCurrentMonth == true && date == coreViewModel.unwrappedTodayDate .getDate() .toString() .padStart(2, "0") ); }, ); const eventCount: React.State = React.createProxyState( [mapState], () => mapState.value.size, ); const hasEvents: React.State = React.createProxyState( [eventCount], () => eventCount.value != 0, ); function select() { selectedDate.value = parseInt(date); } function drop() { handleDrop(date); } return ( ); })}
); }