"use client"; import { useState } from "react"; import { formatDistanceToNow } from "date-fns"; import type { SourceState } from "@/lib/types"; import type { ThingsPayload } from "@/lib/schemas/sources/things"; import { CardShell } from "./SourceCard"; // Things "Today" card. Reads the source snapshot; checking a box completes the // to-do in Things 3 (via /api/integrations/things/complete) and refreshes. export function ThingsCard({ state, onRefresh, refreshing, }: { state: SourceState; onRefresh: () => void; refreshing: boolean; }) { const [completing, setCompleting] = useState>(new Set()); const snapshot = state.snapshot; const meta = snapshot?.ok ? `${formatDistanceToNow(new Date(snapshot.fetchedAt))} ago` : undefined; async function complete(id: string) { setCompleting((prev) => new Set(prev).add(id)); await fetch("/api/integrations/things/complete", { method: "POST", headers: { "Content-Type": "application/json" }, body: JSON.stringify({ id }), }); onRefresh(); } let body: React.ReactNode; if (!snapshot) { body = Loading…; } else if (!snapshot.ok) { body = ( {snapshot.error ?? "Couldn't reach Things."}
Needs Things 3 + Automation permission.
); } else { const tasks = (snapshot.payload as ThingsPayload).tasks; body = tasks.length === 0 ? ( Nothing in Today. 🎉 ) : ( ); } return ( {body} ); } function Note({ children, tone }: { children: React.ReactNode; tone?: "error" }) { return (

{children}

); }