fix object editing
This commit is contained in:
@@ -12,14 +12,13 @@ export function ObjectDetailModal(
|
||||
// state
|
||||
const editingTitle = new React.State(messageObject.title);
|
||||
|
||||
const selectedMessageObjectIndex = new React.State(0);
|
||||
const selectedMessageObjectId = new React.State(
|
||||
chat.getMostRecentContentId(messageObject)
|
||||
);
|
||||
const selectedMessageObject = React.createProxyState(
|
||||
[selectedMessageObjectIndex],
|
||||
[selectedMessageObjectId],
|
||||
() =>
|
||||
chat.getObjectContentFromIndex(
|
||||
messageObject,
|
||||
selectedMessageObjectIndex.value
|
||||
)
|
||||
chat.getObjectContentFromId(messageObject, selectedMessageObjectId.value)
|
||||
);
|
||||
|
||||
const didEditContent = new React.State(false);
|
||||
@@ -51,18 +50,16 @@ export function ObjectDetailModal(
|
||||
function saveAndClose() {
|
||||
messageObject.title = editingTitle.value;
|
||||
|
||||
chat.updateObject(
|
||||
messageObject.id,
|
||||
didEditContent.value == true
|
||||
? {
|
||||
isoDateVersionCreated: new Date().toISOString(),
|
||||
id: React.UUID(),
|
||||
if (didEditContent.value == true) {
|
||||
chat.addObjectContent(messageObject, {
|
||||
isoDateVersionCreated: new Date().toISOString(),
|
||||
id: React.UUID(),
|
||||
|
||||
noteContent: editingNoteContent.value,
|
||||
}
|
||||
: undefined
|
||||
);
|
||||
noteContent: editingNoteContent.value,
|
||||
});
|
||||
}
|
||||
|
||||
chat.addObjectAndSend(messageObject);
|
||||
closeModal();
|
||||
}
|
||||
|
||||
@@ -98,12 +95,16 @@ export function ObjectDetailModal(
|
||||
<span class="icon">history</span>
|
||||
<div>
|
||||
<span>{translation.objectVersion}</span>
|
||||
<select bind:value={selectedMessageObjectIndex}>
|
||||
{...messageObject.contentVersions.map((content, index) => (
|
||||
<option value={index}>
|
||||
{new Date(content.isoDateVersionCreated).toLocaleString()}
|
||||
</option>
|
||||
))}
|
||||
<select bind:value={selectedMessageObjectId}>
|
||||
{...chat
|
||||
.getSortedContents(messageObject)
|
||||
.map((content) => (
|
||||
<option value={content.id}>
|
||||
{new Date(
|
||||
content.isoDateVersionCreated
|
||||
).toLocaleString()}
|
||||
</option>
|
||||
))}
|
||||
</select>
|
||||
<span class="icon">arrow_drop_down</span>
|
||||
</div>
|
||||
|
||||
@@ -9,11 +9,18 @@ import { translation } from "../../translations";
|
||||
export function ChatToolView(chat: Chat) {
|
||||
const isShowingObjectModal = new React.State(false);
|
||||
const selectedObject = new React.State<MessageObject | undefined>(undefined);
|
||||
const objectModal = React.createProxyState([selectedObject], () => {
|
||||
if (selectedObject.value == undefined) return <div></div>;
|
||||
const objectModal = React.createProxyState(
|
||||
[chat.objects, selectedObject],
|
||||
() => {
|
||||
if (selectedObject.value == undefined) return <div></div>;
|
||||
|
||||
return ObjectDetailModal(chat, selectedObject.value, isShowingObjectModal);
|
||||
});
|
||||
return ObjectDetailModal(
|
||||
chat,
|
||||
selectedObject.value,
|
||||
isShowingObjectModal
|
||||
);
|
||||
}
|
||||
);
|
||||
|
||||
function createItem() {
|
||||
const newObject = chat.createObjectFromTitle("New item");
|
||||
@@ -23,10 +30,6 @@ export function ChatToolView(chat: Chat) {
|
||||
const itemConverter: React.StateItemConverter<MessageObject> = (
|
||||
messageObject
|
||||
) => {
|
||||
const latestObject = chat.getLatestObjectContent(messageObject);
|
||||
|
||||
if (!latestObject) return <div></div>; //TODO
|
||||
|
||||
function select() {
|
||||
selectedObject.value = messageObject;
|
||||
isShowingObjectModal.value = true;
|
||||
|
||||
Reference in New Issue
Block a user