feat(ImageObjectPreview): skip the loading state if an img has already been cached

This commit is contained in:
Aminejv 2021-09-24 18:17:36 +01:00
parent 4d8514b4dc
commit 0349657281

View File

@ -48,6 +48,9 @@ const ImagePlaceholder = ({ blurhash }) => (
</div>
);
// NOTE(amine): cache
const cidsLoaded = {};
export default function ImageObjectPreview({
url,
file,
@ -55,9 +58,14 @@ export default function ImageObjectPreview({
tag,
...props
}) {
const isCached = cidsLoaded[file.cid];
const previewerRef = React.useRef();
const [isLoading, setLoading] = React.useState(true);
const handleOnLoaded = () => setLoading(false);
const [isLoading, setLoading] = React.useState(isCached);
const handleOnLoaded = () => {
cidsLoaded[file.cid] = true;
setLoading(false);
};
const { isInView } = useInView({
ref: previewerRef,