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 01:47:43 +02:00
|
|
|
import { ChatOptionModal } from "./chatOptionModal";
|
|
|
|
|
import { ItemDetailModal } from "./itemDetailModal";
|
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>;
|
|
|
|
|
|
|
|
|
|
return ItemDetailModal(chat, selectedObject.value, isShowingObjectModal);
|
|
|
|
|
});
|
|
|
|
|
|
2024-07-11 00:47:58 +02:00
|
|
|
function createItem() {
|
2024-07-11 01:47:43 +02:00
|
|
|
chat.createObject({
|
2024-07-11 00:47:58 +02:00
|
|
|
id: React.UUID(),
|
|
|
|
|
title: "new item",
|
|
|
|
|
});
|
|
|
|
|
}
|
|
|
|
|
|
2024-07-11 01:47:43 +02:00
|
|
|
const itemConverter: React.StateItemConverter<MessageObject> = (object) => {
|
|
|
|
|
function select() {
|
|
|
|
|
selectedObject.value = object;
|
|
|
|
|
isShowingObjectModal.value = true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return <button on:click={select}>{object.title}</button>;
|
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 01:47:43 +02:00
|
|
|
<div children:append={[chat.objects, itemConverter]}></div>
|
|
|
|
|
|
|
|
|
|
<div children:set={objectModal}></div>
|
2024-07-10 19:07:58 +02:00
|
|
|
</div>
|
|
|
|
|
);
|
|
|
|
|
}
|