import * as React from "bloatless-react"; import { Chat, MessageObject } from "../../Model/chatModel"; import { icons } from "../../icons"; import { translation } from "../../translations"; export function ObjectDetailModal( chat: Chat, messageObject: MessageObject, isPresented: React.State ) { // state const editingTitle = new React.State(messageObject.title); const selectedMessageObjectId = new React.State( chat.getMostRecentContentId(messageObject) ); const selectedMessageObject = React.createProxyState( [selectedMessageObjectId], () => chat.getObjectContentFromId(messageObject, selectedMessageObjectId.value) ); // properties const didEditContent = new React.State(false); const editingNoteContent = React.createProxyState( [selectedMessageObject], () => selectedMessageObject.value.noteContent ?? "" ); const editingCategory = React.createProxyState( [selectedMessageObject], () => selectedMessageObject.value.categoryName ?? "" ); const editingDate = React.createProxyState( [selectedMessageObject], () => selectedMessageObject.value.date ?? "" ); const editingTime = React.createProxyState( [selectedMessageObject], () => selectedMessageObject.value.time ?? "" ); const editingPriority = React.createProxyState( [selectedMessageObject], () => selectedMessageObject.value.priority ?? 0 ); React.bulkSubscribe( [ editingNoteContent, editingCategory, editingDate, editingTime, editingPriority, ], () => (didEditContent.value = true) ); // methods function handleKeyDown(e: KeyboardEvent) { if (!e.metaKey && !e.ctrlKey) return; switch (e.key) { case "s": e.preventDefault(); saveAndClose(); break; } } function closeModal() { isPresented.value = false; } function saveAndClose() { messageObject.title = editingTitle.value; if (didEditContent.value == true) { chat.addObjectContent(messageObject, { isoDateVersionCreated: new Date().toISOString(), id: React.UUID(), noteContent: editingNoteContent.value, priority: editingPriority.value, categoryName: editingCategory.value, date: editingDate.value, time: editingTime.value, }); } chat.addObjectAndSend(messageObject); closeModal(); } function deleteAndClose() { chat.deleteObject(messageObject); closeModal(); } const input = ( ); isPresented.subscribe(() => setTimeout(() => input.focus(), 100)); return ( ); }