1import { useCallback } from "preact/hooks";2import type { RowOf } from "@nzip/lofi";3import { useLiveQuery, useTableMutations } from "@nzip/lofi/preact";4import { app } from "../app.ts";56/**7 * Author-owned example. This is the whole binding between a declared table and8 * the UI: pick a table from your schema, derive its row type, and wrap the9 * generic store's writes in domain verbs. Replace `tasks` and the methods below10 * with your own model — framework runtime code remains in `@nzip/lofi`.11 */12const tasksTable = app.schema.tasks;1314/** The row type comes straight from the declared schema. */15export type Task = RowOf<typeof tasksTable>;1617export function useTasks() {18 const query = useLiveQuery(() => tasksTable.orderBy("createdAt", "desc"), []);19 const mutations = useTableMutations(tasksTable);2021 // The generic mutation surface also exposes `remove`; this starter only needs22 // insert and a boolean toggle. Add more domain verbs as you grow.23 const create = useCallback(async (text: string) => {24 await mutations.insert({ text, completed: false, createdAt: new Date() });25 }, [mutations.insert]);26 const setCompleted = useCallback(async (id: string, completed: boolean) => {27 await mutations.update(id, { completed });28 }, [mutations.update]);2930 const mutationFailed = mutations.error !== null;3132 return {33 status: query.status === "error" || mutationFailed ? "error" as const : query.status,34 error: query.error ?? mutations.error,35 durability: mutations.durability,36 tasks: query.rows,37 failureKind: query.status === "error" ? "read" as const : "write" as const,38 create,39 setCompleted,40 };41}