Assistants with the tasks each one owns, starred first, as a sidebar.
import { UiSchema } from "@effect/ui"import { Html } from "@effect/ui/html"import * as stylex from "@stylexjs/stylex"import { Schema } from "effect"import type { Persona } from "./ui/uicontext/components/kit/Persona.ts"import { TaskTree, type TreeTask } from "./ui/uicontext/components/kit/TaskTree.ts"import { sx } from "./ui/uicontext/components/Sx.ts"import { color, radius } from "./ui/uicontext/components/tokens.stylex.ts"const Message = UiSchema.TaggedEnum({ ToggledStar: { assistant: Schema.String, on: Schema.Boolean } })const assistants: ReadonlyArray<{ readonly id: string; readonly name: string; readonly persona: Persona; readonly age: string; readonly tasks: ReadonlyArray<TreeTask> }> = [ { id: "accounts", name: "Accounts", persona: { shape: "hexagon", color: "teal" }, age: "now", tasks: [ { id: "alder", title: "Alder Supply says 4410 is paid", href: "#alder", age: "now", unread: true, current: true }, { id: "overdues", title: "Chase the 45-day overdues", href: "#overdues", age: "1h", routine: true }, { id: "statements", title: "Send November statements", href: "#statements", age: "3h" }, ] }, { id: "purchasing", name: "Purchasing", persona: { shape: "square", color: "amber" }, age: "2h", tasks: [ { id: "freight", title: "Match the freight invoices", href: "#freight", age: "2h" }, { id: "packaging", title: "Renew the packaging contract", href: "#packaging", age: "2d" }, ] }, { id: "reports", name: "Reports", persona: { shape: "pill", color: "green" }, age: "1d", tasks: [ { id: "cash", title: "Cash collected — November", href: "#cash", age: "1d", routine: true }, ] },]const styles = stylex.create({ frame: { width: "min(100%, 17rem)", padding: 8, borderRadius: radius.lg, backgroundColor: color.raised } })export const Workspace = Html.component({ name: "WorkspaceTree", model: Schema.Struct({ starred: Schema.Array(Schema.String) }), message: Message,}).make({ init: () => ({ starred: ["accounts"] }), update: { ToggledStar: ($, { assistant, on }) => $.evolve({ starred: (all) => (on ? [...all, assistant] : all.filter((a) => a !== assistant)) }) }, view: (h, model) => { const tree = (a: (typeof assistants)[number]) => ({ ...a, href: `#${a.id}`, starred: model.starred.includes(a.id), onStar: Message.ToggledStar({ assistant: a.id, on: !model.starred.includes(a.id) }), }) return h.div.attrs(sx(styles.frame)).children(TaskTree(h, { label: "Assistants", sections: [ { id: "starred", label: "Starred", assistants: assistants.filter((a) => model.starred.includes(a.id)).map(tree) }, { id: "all", label: "Your assistants", assistants: assistants.filter((a) => !model.starred.includes(a.id)).map(tree) }, ], })) },})Installation
pnpm dlx shadcn@latest add checkfu/uicontext/task-treeUsage
import { TaskTree } from "./ui/uicontext/components/kit/TaskTree.ts"const Message = UiSchema.TaggedEnum({ ToggledStar: { assistant: Schema.String, on: Schema.Boolean } })// starring is the app's: the star asks, and your update moves the assistant between sectionsexport const Assistants = (h: Html.H<typeof Message.Type>, starred: boolean) => TaskTree(h, { label: "Assistants", sections: [{ id: starred ? "starred" : "all", label: starred ? "Starred" : "Your assistants", assistants: [{ id: "accounts", name: "Accounts", persona: { shape: "hexagon", color: "teal" }, href: "/assistants/accounts", age: "now", starred, onStar: Message.ToggledStar({ assistant: "accounts", on: !starred }), tasks: [{ id: "alder-4410", title: "Alder Supply says 4410 is paid", href: "/tasks/alder-4410", age: "now", unread: true }], }], }], })API reference
Options
| Name | Type | Description |
|---|---|---|
labelrequired | string | — |
sectionsrequired | TreeSection<Message>[] | — |