mirror of
https://github.com/filecoin-project/slate.git
synced 2024-11-26 04:19:49 +03:00
feat(ImageObjectPreview): skip the loading state if an img has already been cached
This commit is contained in:
parent
4d8514b4dc
commit
0349657281
@ -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,
|
||||
|
Loading…
Reference in New Issue
Block a user