2024-07-10 19:07:58 +02:00
|
|
|
import * as React from "bloatless-react";
|
|
|
|
|
|
2024-07-11 01:47:43 +02:00
|
|
|
import { Chat, MessageObject } from "../../Model/chatModel";
|
2024-07-11 00:56:06 +02:00
|
|
|
|
2024-07-11 13:05:02 +02:00
|
|
|
import { ObjectDetailModal } from "./objectDetailModal";
|
|
|
|
|
import { ObjectListEntry } from "./objectListEntry";
|
2024-07-11 01:24:06 +02:00
|
|
|
import { translation } from "../../translations";
|
2024-07-10 19:07:58 +02:00
|
|
|
|
|
|
|
|
export function ChatToolView(chat: Chat) {
|
2024-07-11 01:47:43 +02:00
|
|
|
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>;
|
|
|
|
|
|
2024-07-11 13:05:02 +02:00
|
|
|
return ObjectDetailModal(chat, selectedObject.value, isShowingObjectModal);
|
2024-07-11 01:47:43 +02:00
|
|
|
});
|
|
|
|
|
|
2024-07-11 00:47:58 +02:00
|
|
|
function createItem() {
|
2024-07-11 13:05:02 +02:00
|
|
|
const newObject = chat.createObjectFromTitle("New item");
|
|
|
|
|
chat.addObjectAndSend(newObject);
|
2024-07-11 00:47:58 +02:00
|
|
|
}
|
|
|
|
|
|
2024-07-11 13:05:02 +02:00
|
|
|
const itemConverter: React.StateItemConverter<MessageObject> = (
|
|
|
|
|
messageObject
|
|
|
|
|
) => {
|
|
|
|
|
const latestObject = chat.getLatestObjectContent(messageObject);
|
|
|
|
|
|
|
|
|
|
if (!latestObject) return <div></div>; //TODO
|
|
|
|
|
|
2024-07-11 01:47:43 +02:00
|
|
|
function select() {
|
2024-07-11 13:05:02 +02:00
|
|
|
selectedObject.value = messageObject;
|
2024-07-11 01:47:43 +02:00
|
|
|
isShowingObjectModal.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 13:05:02 +02:00
|
|
|
return ObjectListEntry(messageObject, select);
|
2024-07-11 00:56:06 +02:00
|
|
|
};
|
|
|
|
|
|
2024-07-10 19:07:58 +02:00
|
|
|
return (
|
|
|
|
|
<div class="chat-tool-view">
|
2024-07-11 00:47:58 +02:00
|
|
|
<button on:click={createItem}>+</button>
|
|
|
|
|
<hr></hr>
|
2024-07-11 02:09:44 +02:00
|
|
|
<div children:prepend={[chat.objects, itemConverter]}></div>
|
2024-07-11 01:47:43 +02:00
|
|
|
|
|
|
|
|
<div children:set={objectModal}></div>
|
2024-07-10 19:07:58 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|