Export template source from 1a4fa8f940f1ce3bd18662c28f1e9e9ca452e6cd:quixos-instance/packages/todo-react-runtime
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
import fs from "node:fs/promises";
|
||||
import path from "node:path";
|
||||
import { fileURLToPath } from "node:url";
|
||||
import { derived, type RuntimeContext } from "@quixos/camino-package-runtime";
|
||||
|
||||
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
||||
const componentSourcePath = path.join(dirname, "todo-component.mjs");
|
||||
|
||||
export const source = async () => await fs.readFile(componentSourcePath, "utf8");
|
||||
|
||||
export const createComponent = (context: RuntimeContext) => context.objectId;
|
||||
|
||||
export const props = derived(async (context: RuntimeContext) => {
|
||||
const tasks = await context.edge("port:todo-react:subject").resolve();
|
||||
if (tasks.length !== 1) {
|
||||
throw new Error(`Task component ${context.objectId} has ${tasks.length} subjects`);
|
||||
}
|
||||
const titlePort = context.state<string>("port:todo-react:title");
|
||||
const statusPort = context.state<string>("port:todo-react:status");
|
||||
const priorityPort = context.state<string>("port:todo-react:priority");
|
||||
const notesPort = context.state<string>("port:todo-react:notes");
|
||||
const dueDatePort = context.state<string>("port:todo-react:due-date");
|
||||
const energyPort = context.state<string>("port:todo-react:energy");
|
||||
const [title, status, priority, titleLive, statusLive, priorityLive, notesLive, dueDateLive, energyLive] =
|
||||
await Promise.all([
|
||||
titlePort.get(),
|
||||
statusPort.get(),
|
||||
priorityPort.get(),
|
||||
titlePort.live(),
|
||||
statusPort.live(),
|
||||
priorityPort.live(),
|
||||
notesPort.live(),
|
||||
dueDatePort.live(),
|
||||
energyPort.live(),
|
||||
]);
|
||||
const priorityText = priority && priority !== "NORMAL"
|
||||
? ` ${priority.toLowerCase()}`
|
||||
: "";
|
||||
return {
|
||||
task_id: tasks[0],
|
||||
component_id: context.objectId,
|
||||
title: titleLive,
|
||||
status: statusLive,
|
||||
priority: priorityLive,
|
||||
notes: notesLive,
|
||||
due_date: dueDateLive,
|
||||
energy: energyLive,
|
||||
display_label: `[${status ?? "OPEN"}]${priorityText} ${title ?? "Untitled task"}`,
|
||||
};
|
||||
});
|
||||
|
||||
export const stopWatch = () => null;
|
||||
Reference in New Issue
Block a user