22 lines
972 B
TypeScript
22 lines
972 B
TypeScript
import type { Contexts } from "./gen/qx.js";
|
|||
|
|
|
||
|
|
export const createProject = ({ objectId }: Contexts["createProject"]) => objectId;
|
||
|
|
export const addTask = async ({ input, ports }: Contexts["addTask"]) => {
|
||
|
|
const task = await ports.task.construct(input.trim() || "Untitled task");
|
||
|
|
await ports.tasks.connect(task);
|
||
|
|
return task;
|
||
|
|
};
|
||
|
|
export const taskCount = { kind: "derived" as const, get: async ({ ports }: Contexts["taskCountGet"]) =>
|
||
|
|
(await ports.tasks.resolve()).length,
|
||
|
|
};
|
||
|
|
export const searchDocument = { kind: "derived" as const, get: async ({ ports }: Contexts["searchDocumentGet"]) => {
|
||
|
|
const [name, tasks] = await Promise.all([ports.named["name.get"](), ports.tasks["tasks.resolve"]()]);
|
||
|
|
const count = tasks.length;
|
||
|
|
return {
|
||
|
|
title: name || "Untitled project",
|
||
|
|
subtitle: `Project · ${count} ${count === 1 ? "task" : "tasks"}`,
|
||
|
|
keywords: ["project", "workspace", count === 0 ? "empty" : "tasks"],
|
||
|
|
};
|
||
|
|
}};
|
||
|
|
export const stopWatch = () => null;
|