fixing first thumbnail bug

This commit is contained in:
Anthony 2022-06-14 15:43:41 +02:00 committed by Thomas Zarebczan
parent 91e83760d4
commit 90c2272720

View file

@ -8,20 +8,20 @@ export default function useThumbnail(claimThumbnail: ?string, containerRef: any)
const [thumbnail, setThumbnail] = React.useState(FileRenderPlaceholder);
React.useEffect(() => {
if (!claimThumbnail) return;
if (!claimThumbnail) {
return setThumbnail(FileRenderPlaceholder);
}
const timer = setTimeout(() => {
let newThumbnail = claimThumbnail;
if (
containerRef.current &&
containerRef.current.parentElement &&
containerRef.current.parentElement.offsetWidth
) {
// generate the thumbnail url served by the cdn
if (containerRef.current?.parentElement?.offsetWidth) {
const w = containerRef.current.parentElement.offsetWidth;
newThumbnail = getThumbnailCdnUrl({ thumbnail: newThumbnail, width: w, height: w });
}
// update new thumbnail in state
if (newThumbnail !== thumbnail) {
setThumbnail(newThumbnail);
}