add note objects

This commit is contained in:
marlon-erler
2024-07-11 19:29:12 +02:00
parent 0a20c7d1d9
commit 6079aeb087
3 changed files with 35 additions and 10 deletions
+1 -1
View File
@@ -35,7 +35,7 @@ export function AllObjectsView(
) : (
<div
class="grid gap padding"
style="grid-template-columns: repeat(auto-fit, minmax(350px, 1fr))"
style="grid-template-columns: repeat(auto-fill, minmax(350px, 1fr))"
children:prepend={[chat.objects, objectConverter]}
></div>
)
+19 -4
View File
@@ -12,6 +12,8 @@ export function NoteObjectsView(
const objectConverter: React.StateItemConverter<MessageObject> = (
messageObject
) => {
const latest = chat.getMostRecentContent(messageObject);
function select() {
selectedObject.value = messageObject;
isShowingObjectModal.value = true;
@@ -21,22 +23,35 @@ export function NoteObjectsView(
<button class="tile" on:click={select}>
<div>
<b>{messageObject.title}</b>
<span class="secondary">{messageObject.id}</span>
<span class="secondary ellipsis">
{latest.noteContent!.split("\n")[0]}
</span>
</div>
</button>
);
};
const notes = new React.ListState<MessageObject>();
chat.objects.subscribe(() => {
notes.clear();
chat.objects.value.forEach((messageObject) => {
const latest = chat.getMostRecentContent(messageObject);
if (!latest.noteContent) return;
notes.add(messageObject);
});
});
const content = React.createProxyState([chat.objects], () =>
chat.objects.value.size == 0 ? (
notes.value.size == 0 ? (
<div class="flex-column width-100 height-100 align-center justify-center secondary">
{translation.noNotes}
</div>
) : (
<div
class="grid gap padding"
style="grid-template-columns: repeat(auto-fit, minmax(350px, 1fr))"
children:prepend={[chat.objects, objectConverter]}
style="grid-template-columns: repeat(auto-fill, minmax(350px, 1fr))"
children:prepend={[notes, objectConverter]}
></div>
)
);