Files
ontime/apps/client/src/views/cuesheet/cuesheet-table/cuesheet-table-elements/EditableImage.tsx
T
Claude baee028792 fix(cuesheet): reduce image reload flicker when scrolling
Cuesheet rows are virtualized (react-virtuoso), so rows scrolling out
of the small overscan buffer get unmounted, destroying their <img>
elements; scrolling back remounts them from scratch. Native
loading='lazy' on the image compounded this with an extra deferred
load on every remount. Widen the overscan buffer and drop the
redundant lazy attribute so images stay mounted through normal
scroll-and-back gestures.
2026-07-25 18:57:02 +00:00

69 lines
1.7 KiB
TypeScript

import { memo } from 'react';
import Button from '../../../../common/components/buttons/Button';
import Input from '../../../../common/components/input/input/Input';
import style from './EditableImage.module.scss';
interface EditableImageProps {
initialValue: string;
readOnly?: boolean;
updateValue: (newValue: string) => void;
}
export default memo(EditableImage);
function EditableImage({ initialValue, readOnly, updateValue }: EditableImageProps) {
const handleUpdate = (newValue: string) => {
if (newValue === initialValue) {
return;
}
if (newValue !== '' && !newValue.startsWith('http')) {
return;
}
updateValue(newValue);
};
const openInNewTab = () => {
if (initialValue) {
window.open(initialValue, '_blank', 'noopener,noreferrer');
}
};
if (!initialValue && readOnly) {
return null;
}
if (!initialValue) {
return (
<Input
variant='ghosted'
className={style.imageInput}
fluid
placeholder='Paste image URL'
onBlur={(event) => handleUpdate(event.currentTarget.value)}
onKeyDown={(event) => {
if (event.key === 'Enter') {
handleUpdate(event.currentTarget.value);
}
}}
defaultValue={initialValue}
/>
);
}
return (
<div className={style.imageCell}>
{!readOnly && (
<div className={style.overlay}>
<Button onClick={openInNewTab}>Preview</Button>
<Button variant='subtle-destructive' onClick={() => handleUpdate('')}>
Delete
</Button>
</div>
)}
{Boolean(initialValue) && <img src={initialValue} className={style.image} />}
</div>
);
}