2024-07-11 01:47:43 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-11 15:08:25 +02:00
|
|
|
import { Chat, MessageObject } from "../../Model/chatModel";
|
2024-07-11 01:47:43 +02:00
|
|
|
|
|
|
|
|
import { translation } from "../../translations";
|
|
|
|
|
|
2024-07-11 13:05:02 +02:00
|
|
|
export function ObjectDetailModal(
|
2024-07-11 01:47:43 +02:00
|
|
|
chat: Chat,
|
2024-07-11 13:05:02 +02:00
|
|
|
messageObject: MessageObject,
|
2024-07-11 01:47:43 +02:00
|
|
|
isPresented: React.State<boolean>
|
|
|
|
|
) {
|
2024-07-11 14:03:15 +02:00
|
|
|
// state
|
|
|
|
|
const editingTitle = new React.State(messageObject.title);
|
2024-07-11 15:08:25 +02:00
|
|
|
|
2024-07-11 16:45:45 +02:00
|
|
|
const selectedMessageObjectId = new React.State(
|
|
|
|
|
chat.getMostRecentContentId(messageObject)
|
|
|
|
|
);
|
2024-07-11 15:08:25 +02:00
|
|
|
const selectedMessageObject = React.createProxyState(
|
2024-07-11 16:45:45 +02:00
|
|
|
[selectedMessageObjectId],
|
2024-07-11 15:08:25 +02:00
|
|
|
() =>
|
2024-07-11 16:45:45 +02:00
|
|
|
chat.getObjectContentFromId(messageObject, selectedMessageObjectId.value)
|
2024-07-11 15:08:25 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
const didEditContent = new React.State(false);
|
|
|
|
|
const editingNoteContent = React.createProxyState(
|
|
|
|
|
[selectedMessageObject],
|
|
|
|
|
() => selectedMessageObject.value.noteContent ?? ""
|
|
|
|
|
);
|
|
|
|
|
React.bulkSubscribe(
|
|
|
|
|
[editingNoteContent],
|
|
|
|
|
() => (didEditContent.value = true)
|
2024-07-11 14:03:15 +02:00
|
|
|
);
|
|
|
|
|
|
|
|
|
|
// methods
|
2024-07-11 15:08:25 +02:00
|
|
|
function handleKeyDown(e: KeyboardEvent) {
|
|
|
|
|
if (!e.metaKey && !e.ctrlKey) return;
|
|
|
|
|
|
|
|
|
|
switch (e.key) {
|
|
|
|
|
case "s":
|
|
|
|
|
e.preventDefault();
|
|
|
|
|
saveAndClose();
|
|
|
|
|
break;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 01:47:43 +02:00
|
|
|
function closeModal() {
|
|
|
|
|
isPresented.value = false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function saveAndClose() {
|
2024-07-11 13:05:02 +02:00
|
|
|
messageObject.title = editingTitle.value;
|
2024-07-11 15:08:25 +02:00
|
|
|
|
2024-07-11 16:45:45 +02:00
|
|
|
if (didEditContent.value == true) {
|
|
|
|
|
chat.addObjectContent(messageObject, {
|
|
|
|
|
isoDateVersionCreated: new Date().toISOString(),
|
|
|
|
|
id: React.UUID(),
|
2024-07-11 15:08:25 +02:00
|
|
|
|
2024-07-11 16:45:45 +02:00
|
|
|
noteContent: editingNoteContent.value,
|
|
|
|
|
});
|
|
|
|
|
}
|
2024-07-11 15:08:25 +02:00
|
|
|
|
2024-07-11 16:45:45 +02:00
|
|
|
chat.addObjectAndSend(messageObject);
|
2024-07-11 01:47:43 +02:00
|
|
|
closeModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function deleteAndClose() {
|
2024-07-11 13:05:02 +02:00
|
|
|
chat.deleteObject(messageObject);
|
2024-07-11 01:47:43 +02:00
|
|
|
closeModal();
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return (
|
2024-07-11 15:08:25 +02:00
|
|
|
<div class="modal" toggle:open={isPresented} on:keydown={handleKeyDown}>
|
2024-07-11 01:47:43 +02:00
|
|
|
<div>
|
|
|
|
|
<main>
|
2024-07-11 13:05:02 +02:00
|
|
|
<h2>{messageObject.title}</h2>
|
2024-07-11 14:03:15 +02:00
|
|
|
<span class="secondary">{messageObject.id}</span>
|
|
|
|
|
|
|
|
|
|
<hr></hr>
|
|
|
|
|
|
2024-07-11 16:00:38 +02:00
|
|
|
<div class="flex-column gap">
|
|
|
|
|
<label class="tile">
|
|
|
|
|
<span class="icon">label</span>
|
|
|
|
|
<div>
|
|
|
|
|
<span>{translation.objectTitle}</span>
|
|
|
|
|
<input
|
2024-07-11 18:54:56 +02:00
|
|
|
autofocus
|
2024-07-11 16:00:38 +02:00
|
|
|
bind:value={editingTitle}
|
|
|
|
|
placeholder={translation.objectTitlePlaceholder}
|
|
|
|
|
></input>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
2024-07-11 14:03:15 +02:00
|
|
|
|
2024-07-11 16:00:38 +02:00
|
|
|
<hr></hr>
|
2024-07-11 01:47:43 +02:00
|
|
|
|
2024-07-11 15:10:35 +02:00
|
|
|
<label class="tile">
|
|
|
|
|
<span class="icon">history</span>
|
|
|
|
|
<div>
|
|
|
|
|
<span>{translation.objectVersion}</span>
|
2024-07-11 16:45:45 +02:00
|
|
|
<select bind:value={selectedMessageObjectId}>
|
|
|
|
|
{...chat
|
|
|
|
|
.getSortedContents(messageObject)
|
|
|
|
|
.map((content) => (
|
|
|
|
|
<option value={content.id}>
|
|
|
|
|
{new Date(
|
|
|
|
|
content.isoDateVersionCreated
|
|
|
|
|
).toLocaleString()}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
2024-07-11 15:10:35 +02:00
|
|
|
</select>
|
|
|
|
|
<span class="icon">arrow_drop_down</span>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<label class="tile">
|
|
|
|
|
<span class="icon">sticky_note_2</span>
|
|
|
|
|
<div>
|
|
|
|
|
<span>{translation.noteContent}</span>
|
|
|
|
|
<textarea
|
|
|
|
|
rows="5"
|
|
|
|
|
bind:value={editingNoteContent}
|
|
|
|
|
placeholder={translation.noteContentPlaceholder}
|
|
|
|
|
></textarea>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
2024-07-11 15:08:25 +02:00
|
|
|
|
2024-07-11 16:00:38 +02:00
|
|
|
<hr></hr>
|
2024-07-11 01:47:43 +02:00
|
|
|
|
2024-07-11 16:00:38 +02:00
|
|
|
<button class="danger width-input" on:click={deleteAndClose}>
|
|
|
|
|
{translation.deleteObject}
|
|
|
|
|
<span class="icon">delete</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
2024-07-11 01:47:43 +02:00
|
|
|
</main>
|
|
|
|
|
|
|
|
|
|
<div class="flex-row">
|
|
|
|
|
<button class="flex-1 width-100 danger" on:click={closeModal}>
|
|
|
|
|
{translation.discard}
|
|
|
|
|
</button>
|
|
|
|
|
<button class="flex-1 width-100 primary" on:click={saveAndClose}>
|
|
|
|
|
{translation.save}
|
|
|
|
|
<span class="icon">save</span>
|
|
|
|
|
</button>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|