Uitsnede-dialoog: reset altijd zichtbaar (uitgeschakeld zonder eigen uitsnede), past direct toe en laat de dialoog open

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
2026-11-17 22:22:01 +01:00
co-authored by Claude Sonnet 5.5
parent 1e6534d2ea
commit ed0b6ad61c
3 changed files with 30 additions and 29 deletions
@@ -18,11 +18,13 @@ interface FocusDialogProps {
/** Keeps the change locally: it is sent and made live when the hero is saved, and dropped when the page is left. */
onApply: (imageId: string, request: HeroFocusRequest) => void;
onClose: () => void;
/** The slide has a crop of its own: offers "use the crop of the photo again". */
/** "Use the crop of the photo again": applied at once, the dialog stays open. The button is always shown. */
onReset?: () => void;
/** The slide has a crop of its own; without one there is nothing to reset and the button is disabled. */
canReset?: boolean;
}
export function FocusDialog({ image, onApply, onClose, onReset }: FocusDialogProps) {
export function FocusDialog({ image, onApply, onClose, onReset, canReset = false }: FocusDialogProps) {
const { t } = useTranslation();
return (
<Dialog open={image !== null} onOpenChange={(next) => { if (!next) onClose(); }}>
@@ -31,7 +33,8 @@ export function FocusDialog({ image, onApply, onClose, onReset }: FocusDialogPro
<DialogTitle>{t('hero.focus.title')}</DialogTitle>
</DialogHeader>
{/* Mounted only while open, so every opening starts from the stored values. */}
{image && <FocusEditor image={image} onApply={onApply} onClose={onClose} onReset={onReset} />}
{/* Keyed by the crop it shows, so after a reset it shows the photo's crop. */}
{image && <FocusEditor key={JSON.stringify([image.focus, image.wideFocus, image.tallFocus])} image={image} onApply={onApply} onClose={onClose} onReset={onReset} canReset={canReset} />}
</DialogContent>
</Dialog>
);
@@ -39,7 +42,7 @@ export function FocusDialog({ image, onApply, onClose, onReset }: FocusDialogPro
const percent = (fraction: number) => Math.round(fraction * 1000) / 10;
function FocusEditor({ image, onApply, onClose, onReset }: { image: HeroImageDto; onApply: (imageId: string, request: HeroFocusRequest) => void; onClose: () => void; onReset?: () => void }) {
function FocusEditor({ image, onApply, onClose, onReset, canReset }: { image: HeroImageDto; onApply: (imageId: string, request: HeroFocusRequest) => void; onClose: () => void; onReset?: () => void; canReset: boolean }) {
const { t } = useTranslation();
const area = useRef<HTMLDivElement>(null);
// The whole picture: image.src is already a crop of the wide shape and would be shown stretched and out of place.
@@ -238,16 +241,7 @@ function FocusEditor({ image, onApply, onClose, onReset }: { image: HeroImageDto
<div className="flex flex-wrap justify-end gap-2">
{onReset && (
<Button
type="button"
variant="ghost"
className="mr-auto"
onClick={() => {
onReset();
onClose();
}}
data-testid="focus-reset"
>
<Button type="button" variant="outline" className="mr-auto" disabled={!canReset} onClick={onReset} data-testid="focus-reset">
{t('hero.focus.reset')}
</Button>
)}