import { useEffect, useState } from 'react'; import { loadCameraLensDefaults, removeCameraLensDefault, type CameraLensDefault, } from '../lib/lensDefaults'; interface Props { onClose: () => void; /** Called after a saved row is removed so an open Optics panel can refresh. */ onChanged?: () => void; } const correctionLabel = (entry: CameraLensDefault) => { const corrections = entry.profile.corrections; const enabled = [ corrections.distortion ? 'distortion' : '', corrections.tca ? 'chromatic aberration' : '', corrections.vignetting ? 'vignetting' : '', ].filter(Boolean); return enabled.length ? enabled.join(' · ') : 'no corrections enabled'; }; export default function LensDefaultsModal({ onClose, onChanged }: Props) { const [defaults, setDefaults] = useState(null); const [busy, setBusy] = useState(null); const [error, setError] = useState(null); useEffect(() => { let alive = true; loadCameraLensDefaults() .then((saved) => alive && setDefaults(saved)) .catch((err) => { if (!alive) return; setDefaults([]); setError(err instanceof Error ? err.message : 'Could not load saved defaults'); }); return () => { alive = false; }; }, []); useEffect(() => { const onKey = (e: KeyboardEvent) => { if (e.key !== 'Escape') return; e.preventDefault(); e.stopImmediatePropagation(); if (!busy) onClose(); }; window.addEventListener('keydown', onKey, true); return () => window.removeEventListener('keydown', onKey, true); }, [busy, onClose]); const remove = async (entry: CameraLensDefault) => { const key = `${entry.camera}\u0000${entry.exifLens}`; if (busy) return; setBusy(key); setError(null); try { await removeCameraLensDefault({ camera: entry.camera, lens: entry.exifLens }); setDefaults((current) => current?.filter( (saved) => saved.camera !== entry.camera || saved.exifLens !== entry.exifLens, ) ?? [], ); onChanged?.(); } catch (err) { setError(err instanceof Error ? err.message : 'Could not remove that default'); } finally { setBusy(null); } }; return (
e.target === e.currentTarget && onClose()}>
Settings

Camera lens defaults

These profiles apply automatically on this browser when a new import has the same camera and EXIF lens. Removing one only affects future imports.

{defaults === null ? (

Loading saved defaults…

) : defaults.length === 0 ? (
No camera-lens defaults saved

Open the Optics panel in Develop, choose a lens profile, then use “Set as camera default”.

) : (
{defaults.map((entry) => { const key = `${entry.camera}\u0000${entry.exifLens}`; return (
{entry.profile.maker} {entry.profile.model} crop {entry.profile.crop}×

{entry.camera} + {entry.exifLens}

{correctionLabel(entry)} · saved{' '} {new Date(entry.updatedAt).toLocaleDateString(undefined, { year: 'numeric', month: 'short', day: 'numeric', })}

); })}
)} {error &&

{error}

}
); }