prepare layout for object views
This commit is contained in:
@@ -2,11 +2,18 @@ import * as React from "bloatless-react";
|
||||
|
||||
import { Chat, MessageObject } from "../../Model/chatModel";
|
||||
|
||||
import { AllObjectsView } from "./allObjectsView";
|
||||
import { NoteObjectsView } from "./noteObjectsView";
|
||||
import { ObjectDetailModal } from "./objectDetailModal";
|
||||
import { ObjectListEntry } from "./objectListEntry";
|
||||
import { translation } from "../../translations";
|
||||
|
||||
export const viewTypes = {
|
||||
all: [translation.viewAll, "grid_view"],
|
||||
notes: [translation.viewNotes, "sticky_note_2"],
|
||||
};
|
||||
|
||||
export function ChatObjectView(chat: Chat) {
|
||||
// selection and modal
|
||||
const isShowingObjectModal = new React.State(false);
|
||||
const selectedObject = new React.State<MessageObject | undefined>(undefined);
|
||||
const objectModal = React.createProxyState(
|
||||
@@ -22,6 +29,22 @@ export function ChatObjectView(chat: Chat) {
|
||||
}
|
||||
);
|
||||
|
||||
// view type
|
||||
const selectedViewType = new React.State<keyof typeof viewTypes>("all");
|
||||
const mainView = React.createProxyState([selectedViewType], () => {
|
||||
function getViewFunction() {
|
||||
switch (selectedViewType.value) {
|
||||
case "notes":
|
||||
return NoteObjectsView;
|
||||
default:
|
||||
return AllObjectsView;
|
||||
}
|
||||
}
|
||||
|
||||
return getViewFunction()(chat, selectedObject, isShowingObjectModal);
|
||||
});
|
||||
|
||||
// methods
|
||||
function createObject() {
|
||||
const newObject = chat.createObjectFromTitle(translation.untitledObject);
|
||||
chat.addObjectAndSend(newObject);
|
||||
@@ -29,36 +52,60 @@ export function ChatObjectView(chat: Chat) {
|
||||
isShowingObjectModal.value = true;
|
||||
}
|
||||
|
||||
const objectConverter: React.StateItemConverter<MessageObject> = (
|
||||
messageObject
|
||||
) => {
|
||||
function select() {
|
||||
selectedObject.value = messageObject;
|
||||
isShowingObjectModal.value = true;
|
||||
}
|
||||
|
||||
return ObjectListEntry(messageObject, select);
|
||||
};
|
||||
|
||||
return (
|
||||
<div class="chat-object-view flex-column">
|
||||
<div class="flex-row align-center scroll-h border-bottom">
|
||||
<div class="flex-row align-center border-bottom">
|
||||
<button
|
||||
class="primary"
|
||||
class="primary height-100"
|
||||
on:click={createObject}
|
||||
aria-label={translation.createObject}
|
||||
>
|
||||
<span class="icon">add</span>
|
||||
</button>
|
||||
|
||||
<div class="padding-sm flex flex-row gap justify-center scroll-h width-100">
|
||||
{...Object.keys(viewTypes).map((key: any) =>
|
||||
ViewTypeToggle(key, selectedViewType)
|
||||
)}
|
||||
</div>
|
||||
|
||||
<button
|
||||
class="height-100"
|
||||
on:click={createObject}
|
||||
aria-label={translation.createObject}
|
||||
>
|
||||
<span class="icon">visibility</span>
|
||||
</button>
|
||||
</div>
|
||||
|
||||
<div
|
||||
class="grid gap padding"
|
||||
style="grid-template-columns: repeat(auto-fill, minmax(250px, 1fr))"
|
||||
children:prepend={[chat.objects, objectConverter]}
|
||||
class="width-100 height-100 flex-1 scroll-h"
|
||||
children:set={mainView}
|
||||
></div>
|
||||
|
||||
<div children:set={objectModal}></div>
|
||||
</div>
|
||||
);
|
||||
}
|
||||
|
||||
function ViewTypeToggle(
|
||||
key: keyof typeof viewTypes,
|
||||
selection: React.State<keyof typeof viewTypes>
|
||||
) {
|
||||
const [label, icon] = viewTypes[key];
|
||||
|
||||
function select() {
|
||||
selection.value = key;
|
||||
}
|
||||
|
||||
const isSelected = React.createProxyState(
|
||||
[selection],
|
||||
() => selection.value == key
|
||||
);
|
||||
|
||||
return (
|
||||
<button aria-label={label} on:click={select} toggle:selected={isSelected}>
|
||||
<span class="icon">{icon}</span>
|
||||
</button>
|
||||
);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user