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
|
|
|
|
|
|
|
|
const selectedMessageObjectIndex = new React.State(0);
|
|
|
|
|
const selectedMessageObject = React.createProxyState(
|
|
|
|
|
[selectedMessageObjectIndex],
|
|
|
|
|
() =>
|
|
|
|
|
chat.getObjectContentFromIndex(
|
|
|
|
|
messageObject,
|
|
|
|
|
selectedMessageObjectIndex.value
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
|
chat.updateObject(
|
|
|
|
|
messageObject.id,
|
|
|
|
|
didEditContent.value == true
|
|
|
|
|
? {
|
|
|
|
|
isoDateVersionCreated: new Date().toISOString(),
|
|
|
|
|
id: React.UUID(),
|
|
|
|
|
|
|
|
|
|
noteContent: editingNoteContent.value,
|
|
|
|
|
}
|
|
|
|
|
: undefined
|
|
|
|
|
);
|
|
|
|
|
|
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>
|
|
|
|
|
|
|
|
|
|
<label class="tile">
|
|
|
|
|
<span class="icon">label</span>
|
|
|
|
|
<div>
|
|
|
|
|
<span>{translation.objectTitle}</span>
|
|
|
|
|
<input
|
|
|
|
|
bind:value={editingTitle}
|
|
|
|
|
placeholder={translation.objectTitlePlaceholder}
|
|
|
|
|
></input>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
|
|
|
|
|
|
|
|
|
<hr></hr>
|
2024-07-11 01:47:43 +02:00
|
|
|
|
2024-07-11 14:03:15 +02:00
|
|
|
<label class="tile">
|
|
|
|
|
<span class="icon">history</span>
|
|
|
|
|
<div>
|
|
|
|
|
<span>{translation.objectVersion}</span>
|
2024-07-11 15:08:25 +02:00
|
|
|
<select bind:value={selectedMessageObjectIndex}>
|
|
|
|
|
{...messageObject.contentVersions.map((content, index) => (
|
|
|
|
|
<option value={index}>
|
2024-07-11 14:03:15 +02:00
|
|
|
{new Date(content.isoDateVersionCreated).toLocaleString()}
|
|
|
|
|
</option>
|
|
|
|
|
))}
|
|
|
|
|
</select>
|
|
|
|
|
<span class="icon">arrow_drop_down</span>
|
|
|
|
|
</div>
|
|
|
|
|
</label>
|
2024-07-11 01:47:43 +02:00
|
|
|
|
2024-07-11 15:08:25 +02:00
|
|
|
<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 01:47:43 +02:00
|
|
|
<hr></hr>
|
|
|
|
|
|
2024-07-11 14:03:15 +02:00
|
|
|
<button class="danger width-input" on:click={deleteAndClose}>
|
2024-07-11 01:47:43 +02:00
|
|
|
{translation.deleteObject}
|
|
|
|
|
<span class="icon">delete</span>
|
|
|
|
|
</button>
|
|
|
|
|
</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>
|
|
|
|
|
);
|
|
|
|
|
}
|