Files
photoreport/apps/app/src/library/Autopilot.tsx
sparkandClaude Opus 5.5 67765899a6
ci / rust (pull_request) Successful in 12m32s
ci / typescript (pull_request) Successful in 15m46s
Autopilot edits the agencies' way: tight handball framing, a finishing look, neutral whites.
Measured on kolektiff images (600 EHF/IHF handball photos, 2025-26) and Getty/AFP (1093 action photos, Paris 2024):
- Framing "tight" (default): the subject about as tall as the crop, legs cut mid-shin or mid-thigh (never at a
  joint, never below the ball), the photo's own shape. The second pick of a burst gets the whole-body frame.
  A crop over 92% of the width is not made: the photo stays as shot.
- Look "agency" (default, kolektiff) or "natural" (Getty): vibrance, clarity, texture, slightly cool shadows,
  capture sharpening, noise reduction by ISO. Never a vignette or anything local (ethics rules).
- Defaults: white balance on, 75% of the automatic tone.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_017sovZz1NXBwx4VySojoyA1
2026-10-19 03:30:17 +00:00

207 lines
10 KiB
TypeScript

import { AutopilotSettings } from "@photoreport/contracts";
import type { ApiClient, AutopilotStyle, DeliveryTarget, EventSummary } from "@photoreport/sdk";
import { useEffect, useState } from "react";
import { t } from "../i18n.js";
import { ZerozeroGamePicker } from "./ZerozeroGame.js";
/**
* Autopilot for the open event (docs/photo-editing-rules.md): photos arriving by FTP or the desktop app's ingest
* are edited (tone, level, crop) and the best frames of each burst picked, and optionally delivered.
*/
export function AutopilotButton(props: { api: ApiClient; event: EventSummary; targets: DeliveryTarget[]; canEdit: boolean; onSaved: (e: EventSummary) => void }) {
const L = t.autopilot;
const [open, setOpen] = useState(false);
const [s, setS] = useState<AutopilotSettings>(() => AutopilotSettings.parse(props.event.autopilot ?? {}));
const [state, setState] = useState<"idle" | "saving" | "error">("idle");
useEffect(() => setS(AutopilotSettings.parse(props.event.autopilot ?? {})), [props.event]);
const save = async (next: AutopilotSettings) => {
setS(next);
setState("saving");
try {
props.onSaved(await props.api.updateEvent(props.event.id, { autopilot: next }));
setState("idle");
} catch {
setState("error");
}
};
const check = (key: "crop" | "level" | "tone" | "whiteBalance") => (
<label key={key} className="flex items-center gap-2">
<input type="checkbox" disabled={!props.canEdit} checked={s[key]} onChange={(e) => void save({ ...s, [key]: e.target.checked })} />
<span>{L[key]}</span>
</label>
);
return (
<div className="relative">
<button
onClick={() => setOpen((o) => !o)}
aria-expanded={open}
className={`flex h-6 items-center gap-1.5 border border-black px-2.5 text-[12px] ${s.enabled ? "bg-accent text-white" : "bg-cell text-ink hover:bg-cell-on"}`}
>
{L.button}
</button>
{open && (
<div className="absolute right-0 top-7 z-30 w-[360px] space-y-3 border border-black bg-panel p-3 text-[12px] shadow-xl" role="dialog" aria-label={L.button}>
<label className="flex items-center justify-between gap-2">
<span className="font-semibold uppercase tracking-wide text-ink">{L.button}</span>
<input type="checkbox" disabled={!props.canEdit} checked={s.enabled} onChange={(e) => void save({ ...s, enabled: e.target.checked })} aria-label={L.enable} />
</label>
<p className="text-faint">{L.help}</p>
<fieldset className="grid grid-cols-2 gap-1.5" disabled={!s.enabled || !props.canEdit}>
{check("crop")}
{check("level")}
{check("tone")}
{check("whiteBalance")}
</fieldset>
<label className="block">
<span className="text-faint">{L.toneStrength(Math.round(s.toneStrength * 100))}</span>
<input type="range" min={0} max={100} value={Math.round(s.toneStrength * 100)} disabled={!s.enabled || !s.tone || !props.canEdit} className="w-full" onChange={(e) => setS({ ...s, toneStrength: Number(e.target.value) / 100 })} onPointerUp={() => void save(s)} />
</label>
<label className="flex items-center justify-between gap-2" title={L.framingHelp}>
<span>{L.framing}</span>
<select className="h-6 border border-black bg-cell px-1" disabled={!s.enabled || !s.crop || !props.canEdit} value={s.framing} onChange={(e) => void save({ ...s, framing: e.target.value as AutopilotSettings["framing"] })}>
<option value="tight">{L.framingTight}</option>
<option value="full">{L.framingFull}</option>
</select>
</label>
<label className="flex items-center justify-between gap-2" title={L.lookHelp}>
<span>{L.look}</span>
<select className="h-6 border border-black bg-cell px-1" disabled={!s.enabled || !props.canEdit} value={s.look} onChange={(e) => void save({ ...s, look: e.target.value as AutopilotSettings["look"] })}>
<option value="agency">{L.lookAgency}</option>
<option value="natural">{L.lookNatural}</option>
<option value="none">{L.lookNone}</option>
</select>
</label>
<label className="flex items-center justify-between gap-2">
<span>{L.picksPerBurst}</span>
<select className="h-6 border border-black bg-cell px-1" disabled={!s.enabled || !props.canEdit} value={s.picksPerBurst} onChange={(e) => void save({ ...s, picksPerBurst: Number(e.target.value) })}>
{[0, 1, 2, 3].map((n) => (
<option key={n} value={n}>
{n === 0 ? L.noPicks : n}
</option>
))}
</select>
</label>
<label className="flex items-center justify-between gap-2">
<span>{L.minLongEdge}</span>
<select className="h-6 border border-black bg-cell px-1" disabled={!s.enabled || !props.canEdit} value={s.minLongEdge} onChange={(e) => void save({ ...s, minLongEdge: Number(e.target.value) })}>
{[1600, 2400, 3000, 4000].map((n) => (
<option key={n} value={n}>
{n} px
</option>
))}
</select>
</label>
<label className="flex items-center justify-between gap-2">
<span>{L.deliver}</span>
<select className="h-6 max-w-[180px] border border-black bg-cell px-1" disabled={!s.enabled || !props.canEdit} value={s.deliverTargetId ?? ""} onChange={(e) => void save({ ...s, deliverTargetId: e.target.value || null })}>
<option value="">{L.noDelivery}</option>
{props.targets.map((x) => (
<option key={x.id} value={x.id}>
{x.name}
</option>
))}
</select>
</label>
<label className="flex items-center justify-between gap-2">
<span>{L.selection}</span>
<select className="h-6 max-w-[180px] border border-black bg-cell px-1" disabled={!s.enabled || !props.canEdit} value={s.selection} onChange={(e) => void save({ ...s, selection: e.target.value as AutopilotSettings["selection"] })}>
<option value="bursts">{L.selectionBursts}</option>
<option value="best">{L.selectionBest}</option>
</select>
</label>
{s.selection === "best" && (
<label className="flex items-center justify-between gap-2">
<span>{L.bestCount}</span>
<input
type="number"
min={5}
max={300}
disabled={!s.enabled || !props.canEdit}
value={s.bestCount}
onChange={(e) => setS({ ...s, bestCount: Math.max(5, Math.min(300, Number(e.target.value) || 5)) })}
onBlur={() => void save(s)}
className="h-6 w-20 border border-black bg-[#161617] px-1 text-ink"
/>
</label>
)}
{s.selection === "best" && <p className="text-faint">{L.bestHelp}</p>}
{s.selection === "best" && (
<label className="flex items-center justify-between gap-2">
<span>{L.restTarget}</span>
<select
className="h-6 max-w-[180px] border border-black bg-cell px-1"
disabled={!s.enabled || !props.canEdit}
value={s.restTargetId ?? ""}
onChange={(e) => void save({ ...s, restTargetId: e.target.value || null })}
>
<option value="">{L.noDelivery}</option>
{props.targets
.filter((x) => x.id !== s.deliverTargetId)
.map((x) => (
<option key={x.id} value={x.id}>
{x.name}
</option>
))}
</select>
</label>
)}
{s.selection === "best" && s.restTargetId && <p className="text-faint">{L.restHelp}</p>}
{s.deliverTargetId && props.targets.find((x) => x.id === s.deliverTargetId)?.kind === "ZEROZERO" && (
<ZerozeroGamePicker api={props.api} orgId={props.event.organizationId} targetId={s.deliverTargetId} eventId={props.event.id} />
)}
{state === "error" && <p className="text-danger">{t.unexpectedError}</p>}
{state === "saving" && <p className="text-faint">…</p>}
<Learnt api={props.api} event={props.event} />
</div>
)}
</div>
);
}
const fmt = (key: string, v: number) => {
const sign = v > 0 ? "+" : "";
if (key === "light.exposure") return `${sign}${v.toFixed(2).replace(".", ",")} EV`;
if (key === "wb.temp") return `${sign}${Math.round(v)} K`;
return `${sign}${Math.round(v)}`;
};
/** What the autopilot learnt from the signed-in photographer's corrections (at this venue when it has enough). */
export function Learnt({ api, event }: { api: ApiClient; event: EventSummary }) {
const L = t.autopilot;
const [style, setStyle] = useState<AutopilotStyle | null | undefined>(undefined);
useEffect(() => {
api.autopilotStyle(event.organizationId, event.venue).then((r) => setStyle(r.style), () => setStyle(null));
}, [api, event.organizationId, event.venue]);
if (style === undefined) return null;
const learnt = style && (Object.keys(style.offsets).length > 0 || style.cropFactor);
return (
<div className="border-t border-line pt-2">
<p className="font-semibold text-ink">{L.learnt}</p>
{!style ? (
<p className="text-faint">{L.nothingLearnt}</p>
) : !learnt ? (
<p className="text-faint">{L.learning(style.samples)}</p>
) : (
<>
<ul className="my-1 flex flex-wrap gap-x-3 gap-y-0.5 font-mono text-[11px] text-muted">
{Object.entries(style.offsets).map(([k, v]) => (
<li key={k}>
{L.controls[k] ?? k} {fmt(k, v)}
</li>
))}
{style.cropFactor && <li>{L.tighter(Math.round((1 - style.cropFactor) * 100))}</li>}
</ul>
<p className="text-faint">
{L.learntHelp(style.samples, style.venue)}{" "}
<button className="underline hover:text-ink" onClick={() => void api.forgetAutopilotStyle(event.organizationId).then(() => setStyle(null), () => {})}>
{L.forget}
</button>
</p>
</>
)}
</div>
);
}