b9e42c3ef4
Build and Deploy / build-and-deploy (push) Has been cancelled
- lit-force-graph: Refactored for instance reuse, better lifecycle management, and added dynamic imports for AR/VR modes. - lit-html-table: Improved visual design, readability of headers, and fixed reactivity in editable mode. - lit-draggable-dom: Fixed clipping issues by switching to relative/absolute positioning and resolved a panning speed bug caused by CSS variable inheritance.
95 lines
2.7 KiB
TypeScript
95 lines
2.7 KiB
TypeScript
import { html, css, LitElement } from "lit";
|
|
import { customElement, state } from "lit/decorators.js";
|
|
import { RxDatabase, RxDocument } from "rxdb";
|
|
import { actionButton } from "../components/app-bar";
|
|
import { appDialog } from "../components/app-dialog";
|
|
import { appScaffold } from "../components/app-scaffold";
|
|
import { formBuilder, input, inputValue } from "../components/form-builder";
|
|
import { listViewBuilder } from "../components/list-view";
|
|
import { dbProvider, queryBuilder, Schema } from "../services/database";
|
|
import { Todo } from "../services/todos";
|
|
|
|
@customElement("todo-view")
|
|
export class TodoView extends LitElement {
|
|
static styles = css``;
|
|
@state() showNew = false;
|
|
|
|
render() {
|
|
return dbProvider((db) => {
|
|
db.todos.$.subscribe(() => {
|
|
this.requestUpdate();
|
|
});
|
|
return appScaffold({
|
|
title: "TODOS",
|
|
root: this.shadowRoot!,
|
|
actions: [
|
|
actionButton("delete", async () => {
|
|
await db.todos.remove();
|
|
this.requestUpdate();
|
|
}),
|
|
actionButton("add", async () => {
|
|
this.showNew = !this.showNew;
|
|
}),
|
|
],
|
|
body: () => {
|
|
return html`
|
|
${queryBuilder<Todo>(db.todos.find(), (res) => {
|
|
if (Array.isArray(res)) {
|
|
return listViewBuilder(res, (item) => {
|
|
return this.buildItem(db, item);
|
|
});
|
|
}
|
|
return this.buildItem(db, res);
|
|
})}
|
|
${appDialog({
|
|
title: "New Todo",
|
|
open: this.showNew,
|
|
dismiss: () => {
|
|
if (this.showNew) this.showNew = false;
|
|
},
|
|
content: () => {
|
|
return html`
|
|
${formBuilder(
|
|
html` ${input("title", "Title", { required: true })} `,
|
|
async (form) => {
|
|
await db.todos.insert({
|
|
id: `${Date.now()}`,
|
|
title: inputValue(form, "title"),
|
|
});
|
|
this.showNew = false;
|
|
}
|
|
)}
|
|
`;
|
|
},
|
|
})}
|
|
`;
|
|
},
|
|
});
|
|
});
|
|
}
|
|
|
|
buildItem(db: RxDatabase<Schema>, item: RxDocument<Todo>) {
|
|
return html` <div>
|
|
<input
|
|
.value=${item.title}
|
|
@change=${async (e: any) => {
|
|
const value = e.target.value;
|
|
await db.todos.upsert({
|
|
...item.toJSON(),
|
|
title: value,
|
|
});
|
|
this.requestUpdate();
|
|
}}
|
|
/>
|
|
<button
|
|
@click=${async () => {
|
|
await item.remove();
|
|
this.requestUpdate();
|
|
}}
|
|
>
|
|
Delete
|
|
</button>
|
|
</div>`;
|
|
}
|
|
}
|