ubiquitous-invention/apps/web/components/whiteboard/shapes/project-card.tsx

168 lines
5 KiB
TypeScript
Raw Normal View History

"use client";
import { FolderKanban, ListChecks, Users } from "lucide-react";
import {
BaseBoxShapeUtil,
HTMLContainer,
T,
type TLBaseShape,
toDomPrecision,
} from "tldraw";
import { cn } from "@/lib/utils";
export type ProjectCardShape = TLBaseShape<
"project-card",
{
w: number;
h: number;
objectId: string;
title: string;
taskCount: number;
memberCount: number;
progress: number;
}
>;
chore(lint+types): green pnpm lint && pnpm type-check from a clean clone Path-A first task: get the repo's two repo-wide quality gates passing. Both were failing from a clean clone in ways that were silently hiding each other. Headline fixes: * apps/web: add an eslint 9 flat config (eslint.config.mjs) using FlatCompat against next/core-web-vitals + next/typescript, and switch the `lint` script from `next lint` to `eslint .`. Previously `next lint` fell into its interactive setup prompt because there was no config at all in apps/web, which made `pnpm lint` permanently fail before any rule ever ran. * packages/shared/src/utils/id.ts: replace `randomUUID` from `node:crypto` with `globalThis.crypto.randomUUID`. `@tasks/shared` is forbidden from using Node-only APIs (per AGENTS.md / repo-overview.mdc) because it has to be importable from the browser bundle. Adjacent fixes pulled in to make the gates actually green: * apps/mcp-server/tsconfig.json: drop vestigial rootDir / declaration* / outDir / sourceMap (build is via tsup, not tsc emit) and add allowImportingTsExtensions. The MCP server uses `.ts`-extension re-export shims (db.ts / schema.ts / shared-types.ts) so tsup can inline workspace .ts sources into the bundle. * apps/collab-server/tsconfig.json: same simplification. * apps/mcp-server/package.json: add @types/node so `process.env` in packages/database/src/client.ts (transitively pulled into the MCP server's type-check) resolves. * apps/web/components/ui/input.tsx: empty `interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}` -> `type` alias. * apps/web/server/lib/workspace-guard.ts: `from(args.table as any)` -> `as unknown as PgTable` with a comment. Standard drizzle escape hatch for structural generic tables. * apps/web/components/whiteboard/shapes/{document,project,task}-card.tsx: `BaseBoxShapeUtil<any>` -> `BaseBoxShapeUtil<{Shape}>` plus inline `declare module "@tldraw/tlschema"` augmentation of TLGlobalShapePropsMap. Required adding @tldraw/tlschema as a direct devDep of apps/web so the augmentation target resolves; previously it was only present transitively under tldraw's own deps. Result: `pnpm lint && pnpm type-check` exits 0 across all 6 packages. 16 unused-import / exhaustive-deps warnings remain; they're pre-existing housekeeping and out of scope for this task. Closes plans/Plan-daily-driver-finish/Epic-shipping-the-shell/ Task-fix-lint-and-shared-types.md (status: done). Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 01:11:52 -04:00
declare module "@tldraw/tlschema" {
interface TLGlobalShapePropsMap {
"project-card": ProjectCardShape["props"];
}
}
function clampProgress(n: number): number {
if (Number.isNaN(n)) return 0;
return Math.min(100, Math.max(0, n));
}
function ProjectCardBody({ shape }: { shape: ProjectCardShape }) {
const { title, taskCount, memberCount, progress } = shape.props;
const pct = clampProgress(progress);
return (
<HTMLContainer>
<div
className={cn(
"flex h-full w-full flex-col overflow-hidden rounded-xl border border-[hsl(var(--border))] bg-[hsl(var(--card))] text-[hsl(var(--card-foreground))] shadow-md",
)}
style={{ fontSize: "11px", lineHeight: 1.35 }}
>
<div
className="h-1 w-full shrink-0"
style={{
background: "linear-gradient(90deg, hsl(var(--primary)) 0%, hsl(var(--teal)) 100%)",
}}
aria-hidden
/>
<div className="flex min-h-0 flex-1 flex-col px-3 pb-2 pt-2.5">
<div className="flex min-w-0 items-start gap-2">
<FolderKanban
className="mt-0.5 size-[18px] shrink-0 text-[hsl(var(--primary))]"
strokeWidth={2}
aria-hidden
/>
<div className="min-w-0 flex-1 text-[14px] font-bold leading-tight tracking-tight">
{title || "Untitled project"}
</div>
</div>
<div className="mt-3 grid grid-cols-2 gap-2 text-[11px]">
<div className="flex items-center gap-1.5 rounded-lg bg-[hsl(var(--muted)/0.5)] px-2 py-1.5 text-[hsl(var(--muted-foreground))]">
<ListChecks className="size-3.5 shrink-0 text-[hsl(var(--primary))]" aria-hidden />
<span className="font-medium text-[hsl(var(--card-foreground))]">{taskCount}</span>
<span className="truncate">tasks</span>
</div>
<div className="flex items-center gap-1.5 rounded-lg bg-[hsl(var(--muted)/0.5)] px-2 py-1.5 text-[hsl(var(--muted-foreground))]">
<Users className="size-3.5 shrink-0 text-[hsl(var(--teal))]" aria-hidden />
<span className="font-medium text-[hsl(var(--card-foreground))]">{memberCount}</span>
<span className="truncate">members</span>
</div>
</div>
<div className="mt-3">
<div className="mb-1 flex items-center justify-between text-[10px] text-[hsl(var(--muted-foreground))]">
<span>Progress</span>
<span className="font-semibold tabular-nums text-[hsl(var(--card-foreground))]">{pct}%</span>
</div>
<div
className="h-2 w-full overflow-hidden rounded-full bg-[hsl(var(--muted))]"
role="progressbar"
aria-valuenow={pct}
aria-valuemin={0}
aria-valuemax={100}
>
<div
className="h-full rounded-full transition-[width]"
style={{
width: `${pct}%`,
background: "linear-gradient(90deg, hsl(var(--primary)) 0%, hsl(var(--teal)) 100%)",
}}
/>
</div>
</div>
</div>
<div className="border-t border-[hsl(var(--border)/0.65)] bg-[hsl(var(--muted)/0.35)] px-3 py-1 text-[9px] font-medium uppercase tracking-wider text-[hsl(var(--muted-foreground))]">
Project
</div>
</div>
</HTMLContainer>
);
}
chore(lint+types): green pnpm lint && pnpm type-check from a clean clone Path-A first task: get the repo's two repo-wide quality gates passing. Both were failing from a clean clone in ways that were silently hiding each other. Headline fixes: * apps/web: add an eslint 9 flat config (eslint.config.mjs) using FlatCompat against next/core-web-vitals + next/typescript, and switch the `lint` script from `next lint` to `eslint .`. Previously `next lint` fell into its interactive setup prompt because there was no config at all in apps/web, which made `pnpm lint` permanently fail before any rule ever ran. * packages/shared/src/utils/id.ts: replace `randomUUID` from `node:crypto` with `globalThis.crypto.randomUUID`. `@tasks/shared` is forbidden from using Node-only APIs (per AGENTS.md / repo-overview.mdc) because it has to be importable from the browser bundle. Adjacent fixes pulled in to make the gates actually green: * apps/mcp-server/tsconfig.json: drop vestigial rootDir / declaration* / outDir / sourceMap (build is via tsup, not tsc emit) and add allowImportingTsExtensions. The MCP server uses `.ts`-extension re-export shims (db.ts / schema.ts / shared-types.ts) so tsup can inline workspace .ts sources into the bundle. * apps/collab-server/tsconfig.json: same simplification. * apps/mcp-server/package.json: add @types/node so `process.env` in packages/database/src/client.ts (transitively pulled into the MCP server's type-check) resolves. * apps/web/components/ui/input.tsx: empty `interface InputProps extends React.InputHTMLAttributes<HTMLInputElement> {}` -> `type` alias. * apps/web/server/lib/workspace-guard.ts: `from(args.table as any)` -> `as unknown as PgTable` with a comment. Standard drizzle escape hatch for structural generic tables. * apps/web/components/whiteboard/shapes/{document,project,task}-card.tsx: `BaseBoxShapeUtil<any>` -> `BaseBoxShapeUtil<{Shape}>` plus inline `declare module "@tldraw/tlschema"` augmentation of TLGlobalShapePropsMap. Required adding @tldraw/tlschema as a direct devDep of apps/web so the augmentation target resolves; previously it was only present transitively under tldraw's own deps. Result: `pnpm lint && pnpm type-check` exits 0 across all 6 packages. 16 unused-import / exhaustive-deps warnings remain; they're pre-existing housekeeping and out of scope for this task. Closes plans/Plan-daily-driver-finish/Epic-shipping-the-shell/ Task-fix-lint-and-shared-types.md (status: done). Co-authored-by: Cursor <cursoragent@cursor.com>
2026-06-02 01:11:52 -04:00
export class ProjectCardShapeUtil extends BaseBoxShapeUtil<ProjectCardShape> {
static override type = "project-card";
static override props = {
w: T.number,
h: T.number,
objectId: T.string,
title: T.string,
taskCount: T.number,
memberCount: T.number,
progress: T.number,
};
override getDefaultProps(): ProjectCardShape["props"] {
return {
w: 260,
h: 180,
objectId: "",
title: "Project",
taskCount: 0,
memberCount: 0,
progress: 0,
};
}
override getAriaDescriptor(shape: ProjectCardShape) {
return shape.props.title;
}
override component(shape: ProjectCardShape) {
return <ProjectCardBody shape={shape} />;
}
override indicator(shape: ProjectCardShape) {
return (
<rect
width={toDomPrecision(shape.props.w)}
height={toDomPrecision(shape.props.h)}
rx={10}
ry={10}
/>
);
}
override useLegacyIndicator() {
return false;
}
override getIndicatorPath(shape: ProjectCardShape) {
const p = new Path2D();
p.roundRect(0, 0, shape.props.w, shape.props.h, 10);
return p;
}
}