import "./monthGrid.css"; import * as React from "bloatless-react"; import { MonthGrid } from "../../Model/Files/calendarModel"; import TaskViewModel from "../../ViewModel/Pages/taskViewModel"; import { translations } from "../translations"; import { allowDrop } from "../utility"; import { localeCompare } from "../../Model/Utility/utility"; export function MonthGrid( monthGrid: MonthGrid>, selectedDate: React.State, handleDrop: (date: string) => void ) { const dayLabels: HTMLElement[] = []; let currentWeekday = monthGrid.firstDayOfWeek; while (dayLabels.length < 7) { dayLabels.push( {translations.regional.weekdays.abbreviated[currentWeekday]} ); currentWeekday++; if (currentWeekday == 7) currentWeekday = 0; } const offsetElements: HTMLElement[] = []; console.log(monthGrid.offset); 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: boolean = monthGrid.isCurrentMonth == true && parseInt(date) == new Date().getDate(); 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 ( ); })}
); }