2024-07-18 14:54:11 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
|
|
|
|
import { Chat, MessageObject } from "../../Model/chatModel";
|
|
|
|
|
|
2024-07-18 17:42:41 +02:00
|
|
|
import { DayView } from "./dayView";
|
2024-07-18 22:35:25 +02:00
|
|
|
import { MiniatureDayView } from "./miniatureDayView";
|
2024-07-18 17:42:41 +02:00
|
|
|
import { dayInCalendar } from "../../Model/model";
|
2024-07-18 14:54:11 +02:00
|
|
|
|
|
|
|
|
export function CalendarView(
|
|
|
|
|
chat: Chat,
|
|
|
|
|
messageObjects: React.MapState<MessageObject>,
|
|
|
|
|
selectedObject: React.State<MessageObject | undefined>,
|
|
|
|
|
isShowingObjectModal: React.State<boolean>
|
|
|
|
|
) {
|
2024-07-18 22:35:25 +02:00
|
|
|
let monthGridCells = new React.State<HTMLElement[]>([]);
|
|
|
|
|
|
|
|
|
|
let previousMonth = 0;
|
|
|
|
|
dayInCalendar.subscribe((newValue) => {
|
|
|
|
|
const selectedDate = new Date(newValue);
|
|
|
|
|
if (selectedDate.getMonth() == previousMonth) return;
|
|
|
|
|
|
|
|
|
|
previousMonth = selectedDate.getMonth();
|
|
|
|
|
const currentDate = new Date();
|
|
|
|
|
monthGridCells.value = [];
|
|
|
|
|
|
|
|
|
|
// initialize to first day of month
|
|
|
|
|
currentDate.setDate(1);
|
|
|
|
|
currentDate.setMonth(selectedDate.getMonth());
|
|
|
|
|
|
|
|
|
|
// create blank dates starting sunday
|
|
|
|
|
const monthOffset = currentDate.getDay();
|
|
|
|
|
console.log(monthOffset);
|
|
|
|
|
for (let i = 0; i < monthOffset; i++) {
|
|
|
|
|
monthGridCells.value.push(<div></div>)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// add day views
|
|
|
|
|
while (currentDate.getMonth() == selectedDate.getMonth()) {
|
|
|
|
|
monthGridCells.value.push(
|
|
|
|
|
MiniatureDayView(
|
|
|
|
|
chat,
|
|
|
|
|
messageObjects,
|
|
|
|
|
new Date(currentDate),
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
currentDate.setDate(currentDate.getDate() + 1);
|
|
|
|
|
}
|
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
return (
|
|
|
|
|
<div class="calendar-wrapper">
|
|
|
|
|
<div class="month-grid padding scroll-v">
|
2024-07-18 17:42:41 +02:00
|
|
|
<input type="date" bind:value={dayInCalendar}></input>
|
2024-07-18 22:35:25 +02:00
|
|
|
<div
|
|
|
|
|
class="grid gap"
|
|
|
|
|
style="grid-template-columns: repeat(7, 1fr)"
|
|
|
|
|
children:set={monthGridCells}
|
|
|
|
|
></div>
|
2024-07-18 17:42:41 +02:00
|
|
|
</div>
|
|
|
|
|
{DayView(chat, messageObjects, selectedObject, isShowingObjectModal)}
|
|
|
|
|
</div>
|
2024-07-18 22:35:25 +02:00
|
|
|
);
|
2024-07-18 14:54:11 +02:00
|
|
|
}
|