Files
CT/src/Views/Objects/objectEntryView.tsx
T

77 lines
1.8 KiB
TypeScript
Raw Normal View History

2024-07-11 22:27:15 +02:00
import * as React from "bloatless-react";
import {
Chat,
MessageObject,
MessageObjectContent,
} from "../../Model/chatModel";
import { icons } from "../../icons";
export function ObjectEntryView(
chat: Chat,
messageObject: MessageObject,
selectedObject: React.State<MessageObject | undefined>,
isShowingObjectModal: React.State<boolean>
) {
const latest = chat.getMostRecentContent(messageObject);
function select() {
selectedObject.value = messageObject;
isShowingObjectModal.value = true;
}
2024-07-12 01:05:00 +02:00
function dragStart(event: DragEvent) {
event.dataTransfer?.setData("text", messageObject.id);
}
2024-07-11 22:27:15 +02:00
const fields = {
[icons.noteContent]: "---",
[icons.priority]: "---",
2024-07-12 15:45:26 +02:00
[icons.categoryName]: "---",
2024-07-12 14:30:30 +02:00
[icons.status]: "---",
2024-07-11 22:27:15 +02:00
[icons.date]: "---",
[icons.time]: "---",
};
Object.entries(latest).forEach((entry) => {
let [key, value] = entry as [keyof MessageObjectContent, string];
if (!value) return;
const icon = icons[key];
if (!icon) return;
2024-07-12 14:30:30 +02:00
if (!fields[icon]) return;
2024-07-11 22:27:15 +02:00
fields[icon] = value;
});
const fieldElements = Object.entries(fields).map((field) => {
const [icon, value] = field;
return (
2024-07-12 15:45:26 +02:00
<span class="flex-row control-gap flex align-center padding-right ellipsis">
2024-07-11 22:27:15 +02:00
<span class="icon">{icon}</span>
2024-07-11 22:37:27 +02:00
<span class="ellipsis">{value}</span>
2024-07-11 22:27:15 +02:00
</span>
);
});
return (
2024-07-12 01:05:00 +02:00
<button
2024-07-12 01:42:39 +02:00
class="tile flex-no"
2024-07-12 01:05:00 +02:00
on:click={select}
draggable="true"
on:dragstart={dragStart}
>
2024-07-11 22:27:15 +02:00
<div>
2024-07-12 14:30:30 +02:00
<b class="ellipsis">{chat.getObjectTitle(messageObject)}</b>
2024-07-11 22:27:15 +02:00
<hr></hr>
2024-07-12 15:45:26 +02:00
<span
class="grid height-100 flex secondary"
2024-07-17 14:00:44 +00:00
style="grid-template-columns: 1fr 1fr; grid-template-rows: repeat(3, 1.7rem)"
2024-07-12 15:45:26 +02:00
>
2024-07-11 22:27:15 +02:00
{...fieldElements}
</span>
</div>
</button>
);
}