From e48a2be04474cd50dddbaa47e8470c63f2ea2aa2 Mon Sep 17 00:00:00 2001 From: marlon-erler Date: Fri, 19 Jul 2024 15:53:24 +0200 Subject: [PATCH] add dag&drop for calendar --- dist/index.js | 22 ++++++++++++++++--- src/Views/Objects/calendarView.tsx | 4 ++-- ...miniatureDayView.tsx => monthGridCell.tsx} | 22 ++++++++++++++++++- 3 files changed, 42 insertions(+), 6 deletions(-) rename src/Views/Objects/{miniatureDayView.tsx => monthGridCell.tsx} (78%) diff --git a/dist/index.js b/dist/index.js index ee8862bc..8f758c2e 100644 --- a/dist/index.js +++ b/dist/index.js @@ -1693,8 +1693,8 @@ ); } - // src/Views/Objects/miniatureDayView.tsx - function MiniatureDayView(chat, messageObjects, dateObject) { + // src/Views/Objects/monthGridCell.tsx + function MonthGridCell(chat, messageObjects, dateObject) { const objectsForDayView = new ListState(); const dateString = dateObject.toISOString().split("T")[0]; function processObject(messageObject) { @@ -1722,10 +1722,26 @@ }); return view; }; + function dragOver(event) { + event.preventDefault(); + } + function drop(event) { + event.preventDefault(); + var id = event.dataTransfer?.getData("text"); + if (!id) return; + const messageObject = chat.objects.value.get(id); + if (!messageObject) return; + const newContent = chat.createObjectContent(); + newContent.date = dateString; + chat.updateObjectContent(messageObject, newContent); + chat.addObjectAndSend(messageObject); + } return /* @__PURE__ */ createElement( "button", { "on:click": select, + "on:dragover": dragOver, + "on:drop": drop, "toggle:selected": isSelected, "toggle:today": isToday, class: "day-miniature tile flex-column align-start", @@ -1794,7 +1810,7 @@ } while (currentDate.getUTCMonth() == newSelectedDate.getUTCMonth()) { monthGridCells.value.push( - MiniatureDayView(chat, messageObjects, currentDate) + MonthGridCell(chat, messageObjects, currentDate) ); currentDate.setDate(currentDate.getDate() + 1); } diff --git a/src/Views/Objects/calendarView.tsx b/src/Views/Objects/calendarView.tsx index 7dc0a35f..0972fefc 100644 --- a/src/Views/Objects/calendarView.tsx +++ b/src/Views/Objects/calendarView.tsx @@ -3,7 +3,7 @@ import * as React from "bloatless-react"; import { Chat, MessageObject, MessageObjectWithIndex } from "../../Model/chatModel"; import { DayView } from "./dayView"; -import { MiniatureDayView } from "./miniatureDayView"; +import { MonthGridCell } from "./monthGridCell"; import { dayInCalendar } from "../../Model/model"; import { translation } from "../../translations"; @@ -76,7 +76,7 @@ export function CalendarView( // add day views while (currentDate.getUTCMonth() == newSelectedDate.getUTCMonth()) { monthGridCells.value.push( - MiniatureDayView(chat, messageObjects, currentDate) + MonthGridCell(chat, messageObjects, currentDate) ); currentDate.setDate(currentDate.getDate() + 1); } diff --git a/src/Views/Objects/miniatureDayView.tsx b/src/Views/Objects/monthGridCell.tsx similarity index 78% rename from src/Views/Objects/miniatureDayView.tsx rename to src/Views/Objects/monthGridCell.tsx index 870756dd..2f9bdf66 100644 --- a/src/Views/Objects/miniatureDayView.tsx +++ b/src/Views/Objects/monthGridCell.tsx @@ -5,7 +5,7 @@ import { Chat, MessageObject, MessageObjectWithIndex } from "../../Model/chatMod import { dayInCalendar } from "../../Model/model"; import { getRawObjectIndex } from "../../utility"; -export function MiniatureDayView( +export function MonthGridCell( chat: Chat, messageObjects: | React.ListState @@ -56,9 +56,29 @@ export function MiniatureDayView( return view; }; + function dragOver(event: DragEvent) { + event.preventDefault(); + } + + function drop(event: DragEvent) { + event.preventDefault(); + var id = event.dataTransfer?.getData("text"); + if (!id) return; + + const messageObject = chat.objects.value.get(id); + if (!messageObject) return; + + const newContent = chat.createObjectContent(); + newContent.date = dateString; + chat.updateObjectContent(messageObject, newContent); + chat.addObjectAndSend(messageObject); + } + return (