71 lines
2.3 KiB
TypeScript
71 lines
2.3 KiB
TypeScript
/**
|
|
* rTasks applet definitions — Task Counter + Due Today.
|
|
*/
|
|
|
|
import type { AppletDefinition, AppletLiveData } from "../../shared/applet-types";
|
|
|
|
const taskCounter: AppletDefinition = {
|
|
id: "task-counter",
|
|
label: "Task Counter",
|
|
icon: "📋",
|
|
accentColor: "#0f766e",
|
|
ports: [
|
|
{ name: "board-in", type: "json", direction: "input" },
|
|
{ name: "count-out", type: "number", direction: "output" },
|
|
],
|
|
renderCompact(data: AppletLiveData): string {
|
|
const { snapshot } = data;
|
|
const total = (snapshot.total as number) || 0;
|
|
const done = (snapshot.done as number) || 0;
|
|
const pct = total > 0 ? Math.round((done / total) * 100) : 0;
|
|
|
|
return `
|
|
<div style="text-align:center">
|
|
<div style="font-size:28px;font-weight:700;color:#e2e8f0">${done}/${total}</div>
|
|
<div style="font-size:10px;color:#94a3b8;margin:4px 0 8px">tasks complete</div>
|
|
<div style="background:#334155;border-radius:3px;height:6px;overflow:hidden">
|
|
<div style="background:#0f766e;width:${pct}%;height:100%;border-radius:3px;transition:width 0.3s"></div>
|
|
</div>
|
|
</div>
|
|
`;
|
|
},
|
|
onInputReceived(portName, value, ctx) {
|
|
if (portName === "board-in" && value && typeof value === "object") {
|
|
const board = value as Record<string, unknown>;
|
|
ctx.emitOutput("count-out", Number(board.total) || 0);
|
|
}
|
|
},
|
|
};
|
|
|
|
const dueToday: AppletDefinition = {
|
|
id: "due-today",
|
|
label: "Due Today",
|
|
icon: "⏰",
|
|
accentColor: "#0f766e",
|
|
ports: [
|
|
{ name: "board-in", type: "json", direction: "input" },
|
|
{ name: "tasks-out", type: "json", direction: "output" },
|
|
],
|
|
renderCompact(data: AppletLiveData): string {
|
|
const { snapshot } = data;
|
|
const count = (snapshot.dueCount as number) || 0;
|
|
const urgent = (snapshot.urgentCount as number) || 0;
|
|
const urgColor = urgent > 0 ? "#ef4444" : "#22c55e";
|
|
|
|
return `
|
|
<div style="text-align:center">
|
|
<div style="font-size:32px;font-weight:700;color:#e2e8f0">${count}</div>
|
|
<div style="font-size:10px;color:#94a3b8;margin:4px 0">due today</div>
|
|
<div style="font-size:11px;font-weight:500;color:${urgColor}">${urgent} urgent</div>
|
|
</div>
|
|
`;
|
|
},
|
|
onInputReceived(portName, value, ctx) {
|
|
if (portName === "board-in" && value && typeof value === "object") {
|
|
ctx.emitOutput("tasks-out", value);
|
|
}
|
|
},
|
|
};
|
|
|
|
export const tasksApplets: AppletDefinition[] = [taskCounter, dueToday];
|